#1. Ask an important question I want answered
#1A. What is the average price difference between different brands laptops with a screen size greater than 14 inches and those with 14 inches or smaller, considering only laptops with a storage capacity of 512 GB or more
#1B. Among laptops with processor speeds exceeding 3.5 GHz, which model offers the best balance of performance .
#2. Answer why this question(s) is/are important to I
#2A. This question is important to me as I wish to understand the average price difference between with different screen sizes and storage capacities. Having an answer to this question can provide valuable insights for pricing strategies, product positioning, and consumer preferences. This information could also help manufacturers and retailers adjust their product offerings and pricing strategies to better meet consumer demand and maximize revenue. Also Insights from this analysis can tell us about the product development efforts.
#2B. This question is important to me as I wish to understand because it helps consumers like me to make informed decisions when purchasing laptops. By identifying the model that offers the best balance of performance and price among those with high processor speeds, consumers can ensure they are getting the most value for their money. Also by answering this question we can help a consumer make more informed decisions who wants to buy a particular brand.
#3. Find and collect data (need one dependent variable and more than 3 dependent variables)
#3A. Dependent - Price
#Independent - Screen Size, Storage Capacity, Brand
#3B. Dependent - Price Independent - Processing Speed, RAM Size, Storage Capacity
#4 Describe Ir data (create a data dictionary)
#Ans)
#1. Variable Name - Brand,
#Description - Brand of the laptop,
#Data Type - Text,
#Unit of Measure - N/A
#2. Variable Name - Processor Speed,
#Description - Processing power of the laptop,
#Data Type - Numeric
#Unit of Measure - N/A
#3. Variable Name - RAM Size,
#Description - Size of the Ram for the particular laptop,
#Data Type - Numeric,
#Unit of Measure - N/A
#4. Variable Name - Storage Capacity,
#Description - How much memory can the laptop store,
#Data Type - Numeric,
#Unit of Measure - N/A
#5. Variable Name - Screen Size,
#Description - Size of the lapotop's screen or screen resolution of the laptop,
#Data Type - Numeric,
#Unit of Measure - N/A
#6. Variable Name - Weight,
#Description - Weight of the laptop,
#Data Type - Numeric,
#Unit of Measure - N/A
#7. Variable Name - Price,
#Description - Price of the laptop,
#Data Type - Numeric,
#Unit of Measure - N/A,
library(readr)
library(graphics)
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(ggplot2)
Laptop <- read_csv("/Users/tusharkishan/Desktop/Multivariate/Assignment\ 1/Laptop_price.csv")
## Rows: 202 Columns: 7
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (1): Brand
## dbl (6): Processor_Speed, RAM_Size, Storage_Capacity, Screen_Size, Weight, P...
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
str(Laptop)
## spc_tbl_ [202 × 7] (S3: spec_tbl_df/tbl_df/tbl/data.frame)
## $ Brand : chr [1:202] "Asus" "Acer" "Lenovo" "Acer" ...
## $ Processor_Speed : num [1:202] 3.83 2.91 3.24 3.81 3.27 ...
## $ RAM_Size : num [1:202] 16 4 4 16 32 16 32 4 4 32 ...
## $ Storage_Capacity: num [1:202] 512 1000 256 512 1000 256 256 256 512 512 ...
## $ Screen_Size : num [1:202] 11.2 11.3 11.9 12.3 15 ...
## $ Weight : num [1:202] 2.64 3.26 2.03 4.57 4.19 ...
## $ Price : num [1:202] 17395 31608 9291 17437 32918 ...
## - attr(*, "spec")=
## .. cols(
## .. Brand = col_character(),
## .. Processor_Speed = col_double(),
## .. RAM_Size = col_double(),
## .. Storage_Capacity = col_double(),
## .. Screen_Size = col_double(),
## .. Weight = col_double(),
## .. Price = col_double()
## .. )
## - attr(*, "problems")=<externalptr>
dim(Laptop)
## [1] 202 7
names(Laptop)
## [1] "Brand" "Processor_Speed" "RAM_Size" "Storage_Capacity"
## [5] "Screen_Size" "Weight" "Price"
str(Laptop)
## spc_tbl_ [202 × 7] (S3: spec_tbl_df/tbl_df/tbl/data.frame)
## $ Brand : chr [1:202] "Asus" "Acer" "Lenovo" "Acer" ...
## $ Processor_Speed : num [1:202] 3.83 2.91 3.24 3.81 3.27 ...
## $ RAM_Size : num [1:202] 16 4 4 16 32 16 32 4 4 32 ...
## $ Storage_Capacity: num [1:202] 512 1000 256 512 1000 256 256 256 512 512 ...
## $ Screen_Size : num [1:202] 11.2 11.3 11.9 12.3 15 ...
## $ Weight : num [1:202] 2.64 3.26 2.03 4.57 4.19 ...
## $ Price : num [1:202] 17395 31608 9291 17437 32918 ...
## - attr(*, "spec")=
## .. cols(
## .. Brand = col_character(),
## .. Processor_Speed = col_double(),
## .. RAM_Size = col_double(),
## .. Storage_Capacity = col_double(),
## .. Screen_Size = col_double(),
## .. Weight = col_double(),
## .. Price = col_double()
## .. )
## - attr(*, "problems")=<externalptr>
summary(Laptop)
## Brand Processor_Speed RAM_Size Storage_Capacity
## Length:202 Min. :1.512 Min. : 4.00 Min. : 256.0
## Class :character 1st Qu.:2.028 1st Qu.: 8.00 1st Qu.: 256.0
## Mode :character Median :2.629 Median :16.00 Median : 512.0
## Mean :2.668 Mean :15.88 Mean : 589.9
## 3rd Qu.:3.240 3rd Qu.:32.00 3rd Qu.:1000.0
## Max. :3.992 Max. :32.00 Max. :1000.0
## Screen_Size Weight Price
## Min. :11.01 Min. :2.004 Min. : 8972
## 1st Qu.:12.50 1st Qu.:2.584 1st Qu.:10236
## Median :14.11 Median :3.451 Median :17201
## Mean :14.04 Mean :3.415 Mean :19755
## 3rd Qu.:15.45 3rd Qu.:4.191 3rd Qu.:31520
## Max. :16.98 Max. :4.991 Max. :33151
#Question 1 - What is the average price difference of laptops with a screen size greater than 14 inches and those with 14 inches or smaller, considering only laptops with a storage capacity of 512 GB or more
#attach(Laptop)
ggplot(Laptop, aes(x=Screen_Size,y=Price))+ facet_wrap(Laptop$Storage_Capacity) + geom_point()
#Ans) The picture shows the distribution of the price ranges of different laptops, comparing the screen Sizes and Storage Capacity. The visualization shows us that the average price for laptop with screen size more that 14 inches and storage capacity of 512 gb is around 17,500 dollars and the average price for laptops with a storage capacity of more than 512 gb and a screen size of greater than 14 inches is around 35,000. The average price of screen size less than 14 inches and equal to 512gb is 15,000 and the average price of screen size less than 14 inches and greater than 512 gb is 30,000
#Question 2 - 1. Among laptops with processor speeds exceeding 3.5 GHz, which model offers the best balance of performance.
ggplot(Laptop, aes(x=Processor_Speed, y=Brand)) + geom_hex()
#Ans) The picture shows us the distributiob of different band of laptops with their processing speeds. From the visualiztion it is clear that the model which offers a processing speed exceeding 3.5 H is Dell. Dell has a total count of 6 laptops in which the processing speed is more than 3.5 Hz. After HP, Hp comes in the second place where there are 5 laptops where the processing speed is more than 3.5 Hz. In the last place we get Asus, where there are only two laptops with a processing speed more than 3.5 Hz
#Univariate
ggplot(Laptop, aes(x=Screen_Size, fill=Brand)) + geom_histogram() + theme_bw()
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
#Bivariate
fig <- Laptop[c('RAM_Size','Processor_Speed')]
ggplot(fig, aes(RAM_Size, Processor_Speed)) + geom_boxplot()
## Warning: Continuous x aesthetic
## ℹ did you forget `aes(group = ...)`?
library(readr)
Laptop <- read_csv("/Users/tusharkishan/Desktop/Multivariate/Assignment\ 1/Laptop_price.csv")
## Rows: 202 Columns: 7
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (1): Brand
## dbl (6): Processor_Speed, RAM_Size, Storage_Capacity, Screen_Size, Weight, P...
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
attach(Laptop)
str(Laptop)
## spc_tbl_ [202 × 7] (S3: spec_tbl_df/tbl_df/tbl/data.frame)
## $ Brand : chr [1:202] "Asus" "Acer" "Lenovo" "Acer" ...
## $ Processor_Speed : num [1:202] 3.83 2.91 3.24 3.81 3.27 ...
## $ RAM_Size : num [1:202] 16 4 4 16 32 16 32 4 4 32 ...
## $ Storage_Capacity: num [1:202] 512 1000 256 512 1000 256 256 256 512 512 ...
## $ Screen_Size : num [1:202] 11.2 11.3 11.9 12.3 15 ...
## $ Weight : num [1:202] 2.64 3.26 2.03 4.57 4.19 ...
## $ Price : num [1:202] 17395 31608 9291 17437 32918 ...
## - attr(*, "spec")=
## .. cols(
## .. Brand = col_character(),
## .. Processor_Speed = col_double(),
## .. RAM_Size = col_double(),
## .. Storage_Capacity = col_double(),
## .. Screen_Size = col_double(),
## .. Weight = col_double(),
## .. Price = col_double()
## .. )
## - attr(*, "problems")=<externalptr>
Laptop$Brand <- as.factor(Laptop$Brand)
Laptop_x <- Laptop[, 2:7]
Laptop_x
## # A tibble: 202 × 6
## Processor_Speed RAM_Size Storage_Capacity Screen_Size Weight Price
## <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 3.83 16 512 11.2 2.64 17395.
## 2 2.91 4 1000 11.3 3.26 31608.
## 3 3.24 4 256 11.9 2.03 9291.
## 4 3.81 16 512 12.3 4.57 17437.
## 5 3.27 32 1000 15.0 4.19 32918.
## 6 1.88 16 256 11.9 4.84 9544.
## 7 2.94 32 256 11.7 4.34 10390.
## 8 3.02 4 256 15.6 2.94 9214.
## 9 2.56 4 512 15.0 2.74 16372.
## 10 3.34 32 512 13.6 4.09 18502.
## # ℹ 192 more rows
Laptop_cm <- colMeans(Laptop_x)
Laptop_S <- cov(Laptop_x)
Laptop_d <- apply(Laptop_x, MARGIN = 1, function(Laptop_x)t(Laptop_x - Laptop_cm) %*% solve(Laptop_S) %*% (Laptop_x - Laptop_cm))
Laptop_cm
## Processor_Speed RAM_Size Storage_Capacity Screen_Size
## 2.668461 15.881188 589.861386 14.041607
## Weight Price
## 3.414641 19755.240204
Laptop_S
## Processor_Speed RAM_Size Storage_Capacity Screen_Size
## Processor_Speed 5.116994e-01 0.3185601 -39.88558 -0.05208267
## RAM_Size 3.185601e-01 120.8216344 -315.00163 0.50532863
## Storage_Capacity -3.988558e+01 -315.0016255 100318.74686 -18.13194591
## Screen_Size -5.208267e-02 0.5053286 -18.13195 2.92251221
## Weight -6.897114e-02 0.5549591 33.30079 0.12794149
## Price -1.069043e+03 -3165.3350769 2982291.52657 -483.57174453
## Weight Price
## Processor_Speed -0.06897114 -1069.0428
## RAM_Size 0.55495912 -3165.3351
## Storage_Capacity 33.30079118 2982291.5266
## Screen_Size 0.12794149 -483.5717
## Weight 0.77922054 1009.8840
## Price 1009.88402970 89041543.7240
Laptop_d
## [1] 7.046033 5.864834 6.092269 7.052547 6.392294 7.707943 7.633890
## [8] 3.619055 7.014647 4.008808 8.305302 5.271272 8.941408 5.896180
## [15] 6.298267 7.588683 15.273044 7.174310 6.881232 4.142221 5.237721
## [22] 3.438751 10.348966 3.309893 2.222308 6.621021 5.259605 5.155741
## [29] 4.071710 8.046902 4.337199 6.314830 10.961833 1.402458 7.413982
## [36] 5.762560 7.148697 7.787658 5.313420 3.880694 5.552884 6.522389
## [43] 4.295365 5.520920 7.917105 4.991511 5.389120 10.012804 4.120012
## [50] 2.545658 6.987694 8.577419 6.048998 6.314477 6.889088 4.563280
## [57] 10.118278 3.675721 3.599434 1.608364 5.424325 4.696869 6.070249
## [64] 6.514711 5.661509 8.906266 6.242278 3.102590 8.342990 5.979628
## [71] 5.244768 7.129019 6.978482 12.123856 2.937269 8.368938 4.178966
## [78] 8.974633 10.203353 5.198395 4.476740 6.652942 7.044651 6.375787
## [85] 7.157991 1.914412 5.040103 3.403776 6.455221 4.782349 5.306939
## [92] 5.750407 5.730354 4.785252 5.026523 3.907049 4.067308 7.563906
## [99] 6.589829 4.833864 3.820796 9.632269 7.370329 3.365611 3.533308
## [106] 6.620760 6.674961 5.626567 3.869190 10.011428 8.340499 3.676915
## [113] 4.087691 2.288709 6.185134 6.009560 11.275312 6.815393 4.149578
## [120] 4.626490 5.345928 6.905257 8.798382 6.461096 5.659625 4.211239
## [127] 5.538849 14.721252 2.106452 8.857788 5.351777 4.604412 6.631650
## [134] 5.585505 3.764695 4.952463 8.450256 5.679422 4.108972 5.220052
## [141] 6.099626 4.323482 5.535601 7.451133 3.773314 4.193014 4.117224
## [148] 5.112611 4.034063 7.612710 5.706183 3.751947 4.947560 3.036895
## [155] 6.235761 5.447417 5.306326 9.262790 5.582961 6.841488 5.315029
## [162] 11.063716 7.827539 5.790964 6.496021 5.493243 4.445230 3.784689
## [169] 3.625153 2.106568 1.933387 6.886367 6.549536 5.712459 5.163321
## [176] 6.237538 1.993990 6.046349 6.603949 7.093508 6.394551 8.640492
## [183] 6.018654 8.553014 5.490885 1.545344 5.430700 16.282496 9.792544
## [190] 5.830092 4.416918 4.475758 5.861691 7.449807 6.113447 3.575430
## [197] 2.367714 4.193520 7.551495 4.829163 7.218971 7.855871
#t tests
with(data=Laptop,t.test(Processor_Speed[Brand=="Dell"],Processor_Speed[Brand=="HP"],var.equal=TRUE))
##
## Two Sample t-test
##
## data: Processor_Speed[Brand == "Dell"] and Processor_Speed[Brand == "HP"]
## t = 0.46505, df = 77, p-value = 0.6432
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## -0.2413955 0.3885071
## sample estimates:
## mean of x mean of y
## 2.719753 2.646197
with(data=Laptop,t.test(RAM_Size[Brand=="Dell"],RAM_Size[Brand=="HP"],var.equal=TRUE))
##
## Two Sample t-test
##
## data: RAM_Size[Brand == "Dell"] and RAM_Size[Brand == "HP"]
## t = 1.1226, df = 77, p-value = 0.2651
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## -2.181212 7.819454
## sample estimates:
## mean of x mean of y
## 16.93023 14.11111
with(data=Laptop,t.test(Storage_Capacity[Brand=="Dell"],Storage_Capacity[Brand=="HP"],var.equal=TRUE))
##
## Two Sample t-test
##
## data: Storage_Capacity[Brand == "Dell"] and Storage_Capacity[Brand == "HP"]
## t = -0.009005, df = 77, p-value = 0.9928
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## -142.3460 141.0644
## sample estimates:
## mean of x mean of y
## 581.5814 582.2222
with(data=Laptop,t.test(Screen_Size[Brand=="Dell"],Screen_Size[Brand=="HP"],var.equal=TRUE))
##
## Two Sample t-test
##
## data: Screen_Size[Brand == "Dell"] and Screen_Size[Brand == "HP"]
## t = 1.0016, df = 77, p-value = 0.3197
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## -0.3549872 1.0735740
## sample estimates:
## mean of x mean of y
## 14.39496 14.03567
with(data=Laptop,t.test(Weight[Brand=="Dell"],Weight[Brand=="HP"],var.equal=TRUE))
##
## Two Sample t-test
##
## data: Weight[Brand == "Dell"] and Weight[Brand == "HP"]
## t = 0.90641, df = 77, p-value = 0.3675
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## -0.2257770 0.6030595
## sample estimates:
## mean of x mean of y
## 3.503828 3.315187
with(data=Laptop,t.test(Price[Brand=="Dell"],Price[Brand=="HP"],var.equal=TRUE))
##
## Two Sample t-test
##
## data: Price[Brand == "Dell"] and Price[Brand == "HP"]
## t = 0.056204, df = 77, p-value = 0.9553
## alternative hypothesis: true difference in means is not equal to 0
## 95 percent confidence interval:
## -4100.846 4339.064
## sample estimates:
## mean of x mean of y
## 19575.47 19456.36
#Ans) :The given R code runs numerous studies on the dataset. Initially, it reads the dataset, which is likely to contain numerous features. It then selects all the columns from the dataset, which correspond to the brands "Dell" and "HP," respectively. Following that, the code calculates the means for the specified variables, providing information about their average values.It then computes the covariance matrix to better understand the correlations and variability. Furthermore, the code computes Mahalanobis distances , which assess each observation's distance from the mean in multivariate space while taking covariance into account.Finally, the code uses independent t-tests to compare the means across both the laptop brands "Dell" and "HP". These t-tests seek to determine whether there are statistically significant differences in the means of these variables between the two groups, providing useful information about potential relationships with the outcome variable.The t-value indicates how different the means of the two groups are relative to the variance in the data. A larger t-value suggests a greater difference between the means.The p-value is the probability of observing such an extreme difference in means if the true difference is actually zero. A low p-value (typically below 0.05) suggests that the observed difference is unlikely to be due to random chance.The 95% confidence interval provides a range of values within which we can be 95% confident that the true difference in means lies. In this case, the interval includes zero, indicating that we cannot be confident that there is a true difference between the processor speeds of Dell and HP laptops.
#2) What are the results of Hotelling's T-squared test for all the laptop brands. What is the difference between the variances of laptops with respect to their RAM Size and Price
#Hotelling test
library(Hotelling)
## Loading required package: corpcor
##
## Attaching package: 'Hotelling'
##
## The following object is masked from 'package:dplyr':
##
## summarise
new_test <- hotelling.test(Processor_Speed + RAM_Size + Storage_Capacity + Screen_Size + Weight +Price ~ Brand, data=Laptop)
cat("T2 statistic =",new_test$stat[[1]],"\n")
## T2 statistic = 4.187586
print(new_test)
## Test stat: 4.1876
## Numerator df: 6
## Denominator df: 78
## P-value: 0.6853
#F tests
attach(Laptop)
## The following objects are masked from Laptop (pos = 5):
##
## Brand, Price, Processor_Speed, RAM_Size, Screen_Size,
## Storage_Capacity, Weight
var.test(RAM_Size[Brand=="Asus"],RAM_Size[Brand])
##
## F test to compare two variances
##
## data: RAM_Size[Brand == "Asus"] and RAM_Size[Brand]
## F = 0.99581, num df = 48, denom df = 201, p-value = 0.9775
## alternative hypothesis: true ratio of variances is not equal to 1
## 95 percent confidence interval:
## 0.6554565 1.6105235
## sample estimates:
## ratio of variances
## 0.9958122
var.test(Price[Brand=="Asus"],Price[Brand])
##
## F test to compare two variances
##
## data: Price[Brand == "Asus"] and Price[Brand]
## F = 1.0159, num df = 48, denom df = 201, p-value = 0.9076
## alternative hypothesis: true ratio of variances is not equal to 1
## 95 percent confidence interval:
## 0.6686872 1.6430327
## sample estimates:
## ratio of variances
## 1.015913
#Ans)The Hotelling test uses a T² statistic to compare multiple means simultaneously. The T² statistic value is 4.187586, and it is used to test whether there are significant differences between the means of multiple groups.In this analysis, with a p-value of 0.6853, we do not have enough evidence to reject the null hypothesis, which would suggest that there are no significant differences between the group means.The F tests compares how much the data points vary from the mean within each group relative to the variance between the group means. A value close to 1 suggests that the variances are similar. The ratio of the variances is 0.9958122(RAM_Size) and 1.015913(Price) which means that the variances are similar.The 95% confidence interval provides a range of values within which we can be 95% confident that the true ratio of variances lies. In this case, the interval for both RAM_Size and Price includes 1, indicating that we cannot reject the null hypothesis that the variances are equal.
#4) What result does the multivariate analysis give for each of the variables when we consider all the laptop brands
#Anova
summary(aov(Processor_Speed ~ Brand))
## Df Sum Sq Mean Sq F value Pr(>F)
## Brand 4 1.12 0.2808 0.544 0.704
## Residuals 197 101.73 0.5164
summary(aov(RAM_Size ~ Brand))
## Df Sum Sq Mean Sq F value Pr(>F)
## Brand 4 413 103.2 0.852 0.494
## Residuals 197 23872 121.2
summary(aov(Storage_Capacity ~ Brand))
## Df Sum Sq Mean Sq F value Pr(>F)
## Brand 4 34781 8695 0.085 0.987
## Residuals 197 20129287 102179
summary(aov(Screen_Size ~ Brand))
## Df Sum Sq Mean Sq F value Pr(>F)
## Brand 4 8.8 2.199 0.749 0.56
## Residuals 197 578.6 2.937
summary(aov(Weight ~ Brand))
## Df Sum Sq Mean Sq F value Pr(>F)
## Brand 4 1.04 0.2610 0.33 0.857
## Residuals 197 155.58 0.7897
summary(aov(Price ~ Brand))
## Df Sum Sq Mean Sq F value Pr(>F)
## Brand 4 3.300e+07 8249233 0.091 0.985
## Residuals 197 1.786e+10 90681997
#Manova
summary(manova(as.matrix(Laptop[,-1])~ Brand))
## Df Pillai approx F num Df den Df Pr(>F)
## Brand 4 0.066157 0.54656 24 780 0.9629
## Residuals 197
#Ans)These are the results of analysis of variance (ANOVA) tests conducted to examine the differences in various laptop characteristics (Processor_Speed, RAM_Size, Storage_Capacity, Screen_Size, Weight, Price) across different laptop brands (Brand).Based on these results, none of the variables (Processor_Speed, RAM_Size, Storage_Capacity, Screen_Size, Weight, Price) show a significant difference across different laptop brands, as all p-values are greater than the typical significance level of 0.05. Finally the multivariate analysis of variance (MANOVA) assessing the effect of the "Brand" variable on several dependent variables simultaneously.In this analysis, the p-value of 0.9629 indicates that there is no significant effect of the "Brand" variable on the dependent variable.
library(readr)
Laptop <- read_csv("/Users/tusharkishan/Desktop/Multivariate/Assignment\ 1/Laptop_price.csv")
## Rows: 202 Columns: 7
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (1): Brand
## dbl (6): Processor_Speed, RAM_Size, Storage_Capacity, Screen_Size, Weight, P...
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
attach(Laptop)
## The following objects are masked from Laptop (pos = 3):
##
## Brand, Price, Processor_Speed, RAM_Size, Screen_Size,
## Storage_Capacity, Weight
##
## The following objects are masked from Laptop (pos = 6):
##
## Brand, Price, Processor_Speed, RAM_Size, Screen_Size,
## Storage_Capacity, Weight
str(Laptop)
## spc_tbl_ [202 × 7] (S3: spec_tbl_df/tbl_df/tbl/data.frame)
## $ Brand : chr [1:202] "Asus" "Acer" "Lenovo" "Acer" ...
## $ Processor_Speed : num [1:202] 3.83 2.91 3.24 3.81 3.27 ...
## $ RAM_Size : num [1:202] 16 4 4 16 32 16 32 4 4 32 ...
## $ Storage_Capacity: num [1:202] 512 1000 256 512 1000 256 256 256 512 512 ...
## $ Screen_Size : num [1:202] 11.2 11.3 11.9 12.3 15 ...
## $ Weight : num [1:202] 2.64 3.26 2.03 4.57 4.19 ...
## $ Price : num [1:202] 17395 31608 9291 17437 32918 ...
## - attr(*, "spec")=
## .. cols(
## .. Brand = col_character(),
## .. Processor_Speed = col_double(),
## .. RAM_Size = col_double(),
## .. Storage_Capacity = col_double(),
## .. Screen_Size = col_double(),
## .. Weight = col_double(),
## .. Price = col_double()
## .. )
## - attr(*, "problems")=<externalptr>
#Get the Correlations between the measurements
cor(Laptop[-1])
## Processor_Speed RAM_Size Storage_Capacity Screen_Size
## Processor_Speed 1.00000000 0.04051461 -0.17604245 -0.04259000
## RAM_Size 0.04051461 1.00000000 -0.09047933 0.02689202
## Storage_Capacity -0.17604245 -0.09047933 1.00000000 -0.03348692
## Screen_Size -0.04259000 0.02689202 -0.03348692 1.00000000
## Weight -0.10922694 0.05719505 0.11910591 0.08478188
## Price -0.15837671 -0.03051764 0.99784413 -0.02997688
## Weight Price
## Processor_Speed -0.10922694 -0.15837671
## RAM_Size 0.05719505 -0.03051764
## Storage_Capacity 0.11910591 0.99784413
## Screen_Size 0.08478188 -0.02997688
## Weight 1.00000000 0.12123973
## Price 0.12123973 1.00000000
# Using prcomp to compute the principal components (eigenvalues and eigenvectors).
Laptop_pca <- prcomp(Laptop[,-1],scale=TRUE)
Laptop_pca
## Standard deviations (1, .., p=6):
## [1] 1.44599515 1.06600642 1.00156915 0.95675254 0.92411807 0.01476273
##
## Rotation (n x k) = (6 x 6):
## PC1 PC2 PC3 PC4 PC5
## Processor_Speed -0.22608162 0.32236071 0.47124533 0.5769747 0.53839055
## RAM_Size -0.07530005 -0.37225051 0.82132171 -0.1120121 -0.40849403
## Storage_Capacity 0.67843149 0.10857686 0.08608878 0.1342553 -0.01460891
## Screen_Size -0.01947243 -0.60167347 -0.27017790 0.7268696 -0.19044751
## Weight 0.16620859 -0.61273957 0.05068640 -0.2975645 0.71120396
## Price 0.67449481 0.09090347 0.14276552 0.1401604 -0.03120105
## PC6
## Processor_Speed 0.0115903792
## RAM_Size 0.0421428129
## Storage_Capacity 0.7087260319
## Screen_Size 0.0020169316
## Weight -0.0003609155
## Price -0.7041255995
summary(Laptop_pca)
## Importance of components:
## PC1 PC2 PC3 PC4 PC5 PC6
## Standard deviation 1.4460 1.0660 1.0016 0.9568 0.9241 0.01476
## Proportion of Variance 0.3485 0.1894 0.1672 0.1526 0.1423 0.00004
## Cumulative Proportion 0.3485 0.5379 0.7051 0.8576 1.0000 1.00000
#1 Decide how many Principal Components (PCs) I want to keep and why
#Ans) Based on the summary of the principal component analysis (PCA) on my dataset, I would retain the first three principal components (PCs) as they explain a significant amount of variance in the data.The first three PCs explain a significant proportion of the total variance in the data. Specifically, they explain 70.51% of the variance, with PC1 explaining 34.85%, PC2 explaining 18.94%, and PC3 explaining 16.72%.The cumulative proportion of variance explained by the first three PCs is 0.7051, meaning that these three components capture over 70% of the variability in the original data.By retaining the first three PCs I can effectively reduce the dimensionality of Ir data from six variables to three components, while still retaining a large amount of information about the original variables.Keeping the first three principal components would be a reasonable choice, as they capture a substantial amount of the variance in the data and provide a more compact representation of the original variables. The cumulative proportion reaches 85.76% after the third PC, indicating that adding more PCs beyond the third contributes relatively little to explaining the variance.
(eigen_Laptop <- Laptop_pca$sdev^2)
## [1] 2.0909019711 1.1363696945 1.0031407664 0.9153754298 0.8539941999
## [6] 0.0002179382
names(eigen_Laptop) <- paste("PC",1:5,sep="")
eigen_Laptop
## PC1 PC2 PC3 PC4 PC5 <NA>
## 2.0909019711 1.1363696945 1.0031407664 0.9153754298 0.8539941999 0.0002179382
sumlambdas <- sum(eigen_Laptop)
sumlambdas
## [1] 6
propvar <- eigen_Laptop/sumlambdas
propvar
## PC1 PC2 PC3 PC4 PC5 <NA>
## 3.484837e-01 1.893949e-01 1.671901e-01 1.525626e-01 1.423324e-01 3.632304e-05
cumvar_Laptop <- cumsum(propvar)
cumvar_Laptop
## PC1 PC2 PC3 PC4 PC5 <NA>
## 0.3484837 0.5378786 0.7050687 0.8576313 0.9999637 1.0000000
matlambdas <- rbind(eigen_Laptop,propvar,cumvar_Laptop)
rownames(matlambdas) <- c("Eigenvalues","Prop. variance","Cum. prop. variance")
round(matlambdas,4)
## PC1 PC2 PC3 PC4 PC5 <NA>
## Eigenvalues 2.0909 1.1364 1.0031 0.9154 0.8540 2e-04
## Prop. variance 0.3485 0.1894 0.1672 0.1526 0.1423 0e+00
## Cum. prop. variance 0.3485 0.5379 0.7051 0.8576 1.0000 1e+00
summary(Laptop_pca)
## Importance of components:
## PC1 PC2 PC3 PC4 PC5 PC6
## Standard deviation 1.4460 1.0660 1.0016 0.9568 0.9241 0.01476
## Proportion of Variance 0.3485 0.1894 0.1672 0.1526 0.1423 0.00004
## Cumulative Proportion 0.3485 0.5379 0.7051 0.8576 1.0000 1.00000
Laptop_pca$rotation
## PC1 PC2 PC3 PC4 PC5
## Processor_Speed -0.22608162 0.32236071 0.47124533 0.5769747 0.53839055
## RAM_Size -0.07530005 -0.37225051 0.82132171 -0.1120121 -0.40849403
## Storage_Capacity 0.67843149 0.10857686 0.08608878 0.1342553 -0.01460891
## Screen_Size -0.01947243 -0.60167347 -0.27017790 0.7268696 -0.19044751
## Weight 0.16620859 -0.61273957 0.05068640 -0.2975645 0.71120396
## Price 0.67449481 0.09090347 0.14276552 0.1401604 -0.03120105
## PC6
## Processor_Speed 0.0115903792
## RAM_Size 0.0421428129
## Storage_Capacity 0.7087260319
## Screen_Size 0.0020169316
## Weight -0.0003609155
## Price -0.7041255995
print(Laptop_pca)
## Standard deviations (1, .., p=6):
## [1] 1.44599515 1.06600642 1.00156915 0.95675254 0.92411807 0.01476273
##
## Rotation (n x k) = (6 x 6):
## PC1 PC2 PC3 PC4 PC5
## Processor_Speed -0.22608162 0.32236071 0.47124533 0.5769747 0.53839055
## RAM_Size -0.07530005 -0.37225051 0.82132171 -0.1120121 -0.40849403
## Storage_Capacity 0.67843149 0.10857686 0.08608878 0.1342553 -0.01460891
## Screen_Size -0.01947243 -0.60167347 -0.27017790 0.7268696 -0.19044751
## Weight 0.16620859 -0.61273957 0.05068640 -0.2975645 0.71120396
## Price 0.67449481 0.09090347 0.14276552 0.1401604 -0.03120105
## PC6
## Processor_Speed 0.0115903792
## RAM_Size 0.0421428129
## Storage_Capacity 0.7087260319
## Screen_Size 0.0020169316
## Weight -0.0003609155
## Price -0.7041255995
## Sample scores stored in Laptop_pca$x
Laptop_pca$x
## PC1 PC2 PC3 PC4 PC5
## [1,] -0.81660659 2.012406565 1.124421489 -0.085921187 0.576413679
## [2,] 1.73185241 1.835513200 -0.013372921 -0.440652892 0.746935751
## [3,] -1.79881923 2.177464752 -0.492917304 -0.177049265 0.050409846
## [4,] -0.45458727 0.274899827 1.047099540 -0.290555666 1.993366707
## [5,] 1.65527056 -0.882968168 1.804756280 0.829836868 0.311584112
## [6,] -0.90476280 -0.822865513 -0.341521663 -2.301736592 0.834618971
## [7,] -1.37934003 -0.454074853 1.572723230 -1.528829785 0.661089719
## [8,] -1.60404614 0.127668702 -1.180156460 0.921204315 0.200145674
## [9,] -0.43059121 0.413560941 -1.225512202 0.595488808 -0.275397324
## [10,] -0.44673530 -0.601276267 1.714273823 -0.084737467 0.509502368
## [11,] 1.40027721 1.320959304 0.118881187 1.634721242 0.972927162
## [12,] -0.65971178 0.146403103 2.120544859 0.115433359 0.629852054
## [13,] -0.52236110 1.220330908 -0.728462215 0.388593612 -0.835474308
## [14,] -1.38396046 0.239619449 -0.887094809 -0.592114084 -1.612236079
## [15,] -1.73511340 0.759690576 0.146944074 0.464920726 1.549021612
## [16,] -1.71604682 -1.366501955 1.230979503 1.237829907 0.105582566
## [17,] -1.02430349 -0.154772678 -0.295778576 -2.529322385 0.406425352
## [18,] -2.02635668 -0.108688900 1.407246871 1.522869228 -0.705925269
## [19,] -1.70749468 0.958670764 0.797904303 -0.499394491 1.158148983
## [20,] -1.65936280 -0.195055585 -0.474181115 0.831695475 -0.722612651
## [21,] 1.43141361 0.951531378 0.340618529 1.264455181 -0.817925747
## [22,] 1.75134947 -0.405383116 -0.136071643 1.136800838 -0.564955621
## [23,] 1.87787542 0.761572613 1.168280207 -1.362005319 -1.908650075
## [24,] 1.72095646 0.516923606 -0.002732164 0.475029533 -0.951407600
## [25,] -1.76992582 0.497836947 0.300990882 0.528600308 0.306395991
## [26,] 2.01303425 0.021519800 -1.285466182 0.220213820 -1.281976721
## [27,] -1.49654071 0.777809599 -1.449811745 0.011842075 -0.706615869
## [28,] 1.63978022 1.301945390 -0.809631743 0.802707178 -0.691622622
## [29,] -0.53629517 1.032787095 -0.515126732 0.227679672 -0.182744086
## [30,] 1.20793469 2.327789538 0.564554221 1.265041390 0.200561071
## [31,] 1.88659747 -0.686299859 1.364247213 -0.260051221 -0.497967566
## [32,] -1.46190286 0.319750869 1.113499215 -1.489181260 -0.965607133
## [33,] 1.34840080 -0.535729826 1.494173752 2.101826435 -0.920296483
## [34,] -0.38649211 0.049626072 -0.896591096 0.647105390 -0.199119518
## [35,] -1.16239373 -1.564024155 -1.632131688 0.232293081 0.051578674
## [36,] -1.16310490 -0.469478334 0.079055542 -1.437491175 1.167315992
## [37,] 2.09560642 -2.032659696 0.671896383 0.204214021 -0.829406049
## [38,] -1.15650417 -2.250959740 0.247310337 -0.523673213 -0.682536654
## [39,] -1.52844851 -1.102461650 0.862825338 0.037891934 -0.576880981
## [40,] -1.23094120 -0.580372317 -1.291398720 -0.198118781 0.858865435
## [41,] -1.69119259 0.526831279 0.705545116 0.050308910 1.207973390
## [42,] -1.58142344 -0.991268227 0.460762484 0.390253912 -1.573948931
## [43,] -1.70459394 -0.060206781 1.124178184 0.041306845 -0.972911740
## [44,] -0.59011963 0.883429206 1.814075112 -0.823637762 -0.411844191
## [45,] 2.41126489 -0.361733470 -1.088891996 -1.387753308 0.720809093
## [46,] -0.41485603 -0.491246501 -1.018812473 1.460602804 0.719968418
## [47,] -1.05656263 -1.546670449 -1.595421513 -0.188638752 0.202850844
## [48,] -1.92774231 -0.401860171 0.107170382 2.041534076 0.353571011
## [49,] 1.99192631 0.040523414 -0.947796819 0.161889479 -0.600347293
## [50,] -0.46526440 1.156362731 0.053005060 -0.486131977 -0.755470144
## [51,] 1.94368710 1.576081964 -0.955634539 -0.877620179 -0.830225475
## [52,] -0.56277774 -0.053332157 2.400973958 -0.324513981 1.478940842
## [53,] -1.35011266 0.882187459 -0.301458155 -1.505996069 1.008332205
## [54,] 1.55672048 0.392539114 1.816520335 0.305627170 -0.667604816
## [55,] 2.30501789 0.047077510 -0.601058496 -1.516862857 0.493212639
## [56,] -1.74052761 1.173251404 -0.623025636 0.375322872 0.543717353
## [57,] 2.26933790 -1.587004721 -1.339379292 0.534269512 0.832060803
## [58,] -0.68349614 1.260295881 -0.189558236 0.849981658 1.009096978
## [59,] -0.20487716 -0.585950566 -1.458859069 0.559676123 -0.760268457
## [60,] -0.22256205 -0.241983081 -0.626356331 -0.215977703 -0.965018483
## [61,] -0.16404988 1.002547293 -1.178331307 -1.174924073 -1.175318254
## [62,] -1.60808144 0.862669117 -0.140122969 -0.298690513 -0.718190919
## [63,] 1.85078523 1.159714942 0.298070517 -0.626939432 1.126759088
## [64,] 0.24810574 -0.712856418 -1.079125815 -1.654115226 0.641166568
## [65,] -1.45157298 -0.489550267 -0.735092881 0.559208338 1.728050416
## [66,] 1.56965304 1.312849333 1.848593910 -0.597084832 -1.196334213
## [67,] 1.71101604 0.266258616 1.904357273 -0.527245378 -0.172998957
## [68,] -1.60037311 0.783282081 -0.219467418 -0.293456198 -0.807037786
## [69,] -1.70298321 -0.939577772 0.340961680 1.066529998 -2.026447508
## [70,] -0.31848602 -0.657073306 -0.736003753 0.710093044 0.741158426
## [71,] 2.01995765 -0.444464701 -1.021723145 0.308848608 -0.349005128
## [72,] 1.80803575 1.967613652 -0.770303005 -0.714053439 -0.832551012
## [73,] -1.94471258 0.963792831 -0.819406485 1.763021429 -0.005483762
## [74,] 1.61062347 -1.405180688 2.130132707 1.357747016 1.305523356
## [75,] -0.52462163 0.560226291 -0.369725811 0.426353703 -1.299849952
## [76,] 1.82142378 -1.463880284 0.729256532 1.070311147 -1.420154056
## [77,] -1.59449347 -0.235580947 1.442712811 -0.583821205 -0.019378131
## [78,] -1.64483238 -0.991561445 0.409601671 0.910142695 -1.811171853
## [79,] -0.22997301 -1.315697378 -0.005360192 0.236239955 -2.426027087
## [80,] -0.10951224 1.157032336 -0.717653912 -1.766543864 -0.237725971
## [81,] 1.74858680 0.053684173 0.824020656 0.422479551 1.142035089
## [82,] 1.64112771 -0.326043114 -0.417095962 1.985121094 0.365658012
## [83,] -0.98398464 -0.207585977 -0.551527639 -2.382207089 -0.111349095
## [84,] 0.19030298 -1.084360669 -1.306882780 -0.864716340 1.207029900
## [85,] -0.05417610 -2.466251068 0.376596691 0.210061311 -0.634458849
## [86,] -0.49856660 0.418566468 -0.367994683 0.579648533 0.568194209
## [87,] 2.10343096 0.470675234 -0.137568623 -1.334047375 -0.754384561
## [88,] 0.06069932 -0.528593073 -1.599571362 -0.646879830 0.077271964
## [89,] -1.50261625 0.798489316 -0.266473271 -0.470608980 1.787357870
## [90,] -1.25559099 -1.164254435 0.488242580 -1.025153113 -1.033985243
## [91,] 1.73370912 1.016559584 1.051183954 -0.551390543 0.993232208
## [92,] 1.70222880 0.988471761 -0.845934486 0.672767466 -1.345286514
## [93,] -0.11520108 -0.934673593 0.538604943 -0.893351627 -1.390853923
## [94,] 1.81457545 0.175300158 -0.925404578 0.764220190 -0.807724061
## [95,] -1.79803628 0.924105366 -0.896164109 0.997345167 0.061479340
## [96,] -0.81910650 1.337109036 -0.114531566 1.276636401 0.108093678
## [97,] -1.61961918 -0.197901996 -0.388056652 0.851309434 1.220918952
## [98,] -0.30677716 -0.012289501 1.391327755 -1.346431721 -0.352637984
## [99,] 1.52697708 1.019672964 -0.081529063 1.288196756 0.024872007
## [100,] -0.16971743 -0.176394886 1.042574604 -1.605383399 -0.861149577
## [101,] -0.17967755 -0.776613049 -1.634770722 0.738990335 -0.102558337
## [102,] -1.91259063 1.241183780 2.056760670 -0.409300658 -0.122977627
## [103,] -1.02357588 -1.476065571 0.328418024 -1.737948015 -0.920309117
## [104,] 0.11017447 -1.529048263 -0.806341208 -0.673914837 -0.089242760
## [105,] 2.16596487 -0.333964045 -0.624577406 -0.541950087 0.552586120
## [106,] 2.22845168 0.759911769 -0.913307142 -1.614774814 0.149010639
## [107,] -1.22658424 -1.251169399 0.468757544 -0.938769035 -1.025910474
## [108,] 1.46929508 1.357200565 -0.606062826 1.461884839 -0.481025114
## [109,] -1.53145641 -0.302390707 -0.531366318 0.299940311 -0.617146476
## [110,] 1.23235938 2.069910397 0.462498741 1.327902034 0.210362081
## [111,] -0.35484954 -1.333240678 1.774856080 0.139864569 1.218659187
## [112,] -1.50667704 0.728200700 -1.051612908 -0.275262345 -0.668549391
## [113,] -1.45371240 -0.131268822 -0.786346346 0.034975622 -1.230740064
## [114,] -0.03522255 -1.184441362 -0.192877017 -0.473186338 0.801117871
## [115,] -1.22503335 -0.699439502 -0.873371181 -0.360164684 1.852543337
## [116,] 2.03389892 -0.574482714 1.478080226 -1.154503078 -0.152403201
## [117,] 1.47025167 2.872824354 0.063047016 -0.026328932 -0.111518426
## [118,] -1.65203250 1.398651131 -0.099143165 -0.786841092 -0.977924145
## [119,] 1.68622542 1.634885623 0.194848217 -0.299259711 0.428836878
## [120,] -1.53570767 0.957770390 -1.189411982 -0.054066244 -0.321888524
## [121,] -0.44293184 0.870986505 -1.420550512 0.418351034 -1.035257235
## [122,] -1.73488293 1.234913173 0.239841605 0.019339117 1.424628584
## [123,] -0.26494389 -1.209574163 -0.788199807 1.273062846 1.861776949
## [124,] 1.98244614 1.516102198 -0.389564296 -1.357892233 -0.403396404
## [125,] -0.60441879 -1.089272039 1.603822785 1.076125904 0.444720920
## [126,] 1.84420815 -0.083592098 -0.348983865 0.586794950 0.630812103
## [127,] -1.91102358 0.476437960 1.771801091 0.306837263 -0.194329307
## [128,] 1.70132247 1.494646944 0.724133824 -0.233893533 1.595408527
## [129,] -1.54953696 0.023241468 -0.461044892 0.193908225 -0.742527212
## [130,] -1.31027489 0.262374587 -0.919958403 -1.153148569 -1.554929683
## [131,] -0.12536386 -2.195914392 0.466099727 0.242946014 -0.695886518
## [132,] -0.63280498 0.170344722 1.191074536 0.384865394 -1.340450162
## [133,] -0.20170707 -1.874305370 -0.094559763 0.837987822 1.300156307
## [134,] -0.38166433 0.379147099 1.033369321 -1.085482891 -1.488629424
## [135,] 2.07758926 -0.567298547 -1.027985948 0.199698548 -0.231644442
## [136,] 1.45958025 0.829706855 0.194769246 1.516083239 0.706638786
## [137,] 1.15807363 1.068164040 0.882398529 2.344272216 -0.081786260
## [138,] -1.67955424 1.791108409 -0.844568185 -0.359585369 -0.274867039
## [139,] 2.06594005 -0.463036778 -0.913594572 0.079699389 -0.060829806
## [140,] 2.04508383 -1.178592701 1.258242956 -0.551597621 -0.211993433
## [141,] 2.32848518 -1.121873202 -1.501921676 -0.212781477 0.277597658
## [142,] -0.62008738 1.208817948 -0.042756915 0.477445305 1.442545524
## [143,] 2.19909457 -1.318759961 -1.185252824 0.392496577 0.060378582
## [144,] -1.36968021 0.645603093 -0.226363254 -1.281847756 1.318064738
## [145,] -0.01987145 -1.030653589 -1.512858508 0.165128670 0.501163848
## [146,] -1.47180056 -0.508540902 -1.328253750 0.880021856 0.469285293
## [147,] 1.69581746 -0.528065212 0.346157173 1.357334535 0.465440970
## [148,] -0.46553567 -0.884214205 1.812958241 0.191685349 0.893928062
## [149,] -1.25468275 -0.209745294 -0.609207115 -0.916457951 -0.579522958
## [150,] 2.28961543 -1.723065522 -1.457436700 0.418767815 -0.142416284
## [151,] -1.08140087 -0.251309666 -0.493090150 -1.787889704 -0.101032440
## [152,] -1.93572344 0.826387625 0.391425512 0.994656798 0.092074387
## [153,] -2.00219445 0.829744248 0.206909943 1.400837595 -0.381218730
## [154,] 1.58648723 0.219529098 0.319451631 1.223762782 -0.212252621
## [155,] 1.67729036 0.356074593 2.036671041 -0.373037641 -0.027333817
## [156,] -1.42443172 -1.601441962 1.227565943 -0.037614488 0.609750937
## [157,] -0.28373934 0.076741143 -1.789629418 0.597332341 -1.134228610
## [158,] -0.44937771 0.997318779 0.573678031 -0.590902657 2.246673600
## [159,] 2.00023152 -1.467714905 -0.087407764 0.895956575 0.519743754
## [160,] 1.69722757 2.234837697 -0.344158156 -0.598187692 -0.230204607
## [161,] 1.96892143 0.239551142 -0.308234892 -0.199238758 1.500939343
## [162,] 2.42080576 0.131777867 -0.743792448 -2.164962847 1.179399980
## [163,] 2.10156832 -0.244279176 1.466665086 -1.760588338 -0.322817955
## [164,] -0.36781116 -1.249966349 0.075383103 1.197834974 1.001585389
## [165,] 2.33833393 -0.949703534 -0.098634339 -1.342743864 0.579105562
## [166,] -1.40230118 0.103625344 -0.506421729 -0.281097191 0.975478388
## [167,] -1.32452726 0.492049858 -0.349839074 -1.316675977 -0.574558821
## [168,] -0.09452724 -1.096714590 -0.203392649 -0.371095355 0.685330245
## [169,] -1.18653506 -0.500211272 -1.494219867 -0.460894648 0.443032606
## [170,] -0.16768800 0.141658973 -0.692746567 -0.677094272 0.451281454
## [171,] -0.62563131 1.053872209 0.498227005 0.219230799 0.069086052
## [172,] -1.23081095 -2.334429428 0.381005414 -0.112934329 -0.437117648
## [173,] 1.44881163 1.437192599 0.515797307 0.630085148 -0.736557660
## [174,] -1.14667340 -0.719540803 -1.034961982 -0.653585076 1.611805312
## [175,] -1.68278635 0.250912369 1.489461739 -0.465084806 -0.387655581
## [176,] -0.86080710 1.003738300 -0.500821614 2.056499864 0.319331337
## [177,] -1.63460208 0.377901361 0.305484862 -0.003277031 0.545002805
## [178,] -0.43063911 0.007605337 0.663941378 -0.278227678 -2.106908011
## [179,] 2.22740745 0.117344688 -0.746662070 -1.318956552 0.100142064
## [180,] 2.14067645 -1.624000757 -1.019983396 0.804505557 0.570176389
## [181,] 1.82869908 -0.441334486 1.992484647 -0.456995674 0.606789245
## [182,] -1.38640672 -1.060569331 -0.024153840 -0.264170245 -2.343207666
## [183,] -0.48078134 1.270437461 -0.884062705 0.255020335 -0.273322596
## [184,] 1.80140311 -0.212104543 2.068284861 -0.650690520 0.610362190
## [185,] 0.03095186 -1.365586330 -1.375392002 0.062043870 1.103516590
## [186,] -0.55364299 0.679436011 0.617935783 0.115087809 0.666889883
## [187,] 2.05522582 -0.566735472 -1.532078975 0.623879004 -0.467312215
## [188,] 1.85017057 -1.270750811 0.443950989 0.599579844 -2.040442623
## [189,] -0.33778950 -1.913541477 1.336323254 0.787037132 0.684349093
## [190,] 1.84788409 0.920015841 0.826512633 -0.970764542 0.724122372
## [191,] -0.66410086 -0.546147290 1.230792569 1.130594913 -0.805906877
## [192,] -0.47034357 -0.064839531 1.163460564 -0.358631394 -1.004464792
## [193,] 2.15349719 -1.377445771 -0.940260411 0.493282640 0.588724679
## [194,] -1.95819519 1.124305195 -0.462565672 1.289174556 -0.189522430
## [195,] 1.39434305 0.249962886 0.519159784 2.010119835 -0.017619254
## [196,] -1.52469345 0.285165815 -0.743342512 0.177392492 1.124918798
## [197,] -0.34507636 0.607015633 -1.056688598 0.010282930 -0.861818418
## [198,] -0.58359405 2.041321848 -0.472975595 -0.249350917 0.011259423
## [199,] -1.24625865 -2.172700311 0.590972421 -0.302468439 -0.106771861
## [200,] 0.21234955 -0.908062566 -1.118975759 -1.406462486 0.679971781
## [201,] -1.55058112 -0.421675837 0.582679308 0.250031356 1.744486673
## [202,] -0.93820823 -2.063104605 -0.965851663 -0.678396573 0.268367663
## PC6
## [1,] 0.0181156855
## [2,] -0.0114349045
## [3,] -0.0045004865
## [4,] 0.0151211509
## [5,] 0.0078520147
## [6,] -0.0004311798
## [7,] 0.0148484176
## [8,] 0.0016018473
## [9,] 0.0323505533
## [10,] -0.0087817779
## [11,] -0.0197518929
## [12,] -0.0042411506
## [13,] -0.0361282842
## [14,] -0.0125128964
## [15,] -0.0167227895
## [16,] -0.0170862585
## [17,] 0.0403771733
## [18,] -0.0048718924
## [19,] 0.0218983665
## [20,] 0.0161757967
## [21,] 0.0133301330
## [22,] 0.0022490334
## [23,] -0.0104293245
## [24,] -0.0087565409
## [25,] 0.0003284463
## [26,] -0.0151839239
## [27,] -0.0145836649
## [28,] -0.0100193504
## [29,] 0.0239650067
## [30,] 0.0100951356
## [31,] -0.0004354867
## [32,] -0.0099278759
## [33,] 0.0197859578
## [34,] -0.0022681797
## [35,] 0.0203360392
## [36,] -0.0152161040
## [37,] -0.0049268188
## [38,] 0.0197133219
## [39,] 0.0208419520
## [40,] -0.0079565331
## [41,] -0.0194345596
## [42,] 0.0160550093
## [43,] -0.0107721804
## [44,] 0.0098734495
## [45,] -0.0156719744
## [46,] -0.0125660687
## [47,] -0.0052329723
## [48,] 0.0271504689
## [49,] -0.0138073548
## [50,] -0.0085590069
## [51,] -0.0097478653
## [52,] 0.0003463403
## [53,] 0.0126435300
## [54,] -0.0155290746
## [55,] -0.0160873510
## [56,] 0.0148809245
## [57,] -0.0234726983
## [58,] -0.0028437686
## [59,] -0.0054560766
## [60,] 0.0003662338
## [61,] -0.0019385015
## [62,] -0.0213126312
## [63,] -0.0164646701
## [64,] -0.0175098641
## [65,] -0.0037894514
## [66,] -0.0126925534
## [67,] 0.0134153160
## [68,] -0.0097143569
## [69,] 0.0016162875
## [70,] 0.0288425293
## [71,] 0.0199816720
## [72,] 0.0065775045
## [73,] -0.0079136664
## [74,] 0.0115551990
## [75,] 0.0068629583
## [76,] -0.0128121950
## [77,] 0.0100829313
## [78,] -0.0203604491
## [79,] -0.0192588759
## [80,] -0.0023722256
## [81,] -0.0115563773
## [82,] -0.0117758604
## [83,] 0.0023973549
## [84,] -0.0154711038
## [85,] -0.0157841361
## [86,] 0.0128805691
## [87,] -0.0046601789
## [88,] -0.0055509745
## [89,] -0.0128760887
## [90,] 0.0065673093
## [91,] 0.0089941544
## [92,] -0.0062238876
## [93,] -0.0182543821
## [94,] 0.0142195350
## [95,] 0.0135074119
## [96,] 0.0066943169
## [97,] 0.0044519258
## [98,] 0.0274719371
## [99,] -0.0244344798
## [100,] 0.0023465561
## [101,] 0.0005884054
## [102,] -0.0214409268
## [103,] -0.0109776503
## [104,] 0.0056939497
## [105,] -0.0052014908
## [106,] -0.0026188085
## [107,] -0.0217147822
## [108,] -0.0005424435
## [109,] 0.0200321753
## [110,] 0.0269124539
## [111,] -0.0198908073
## [112,] 0.0095217615
## [113,] -0.0120873633
## [114,] -0.0021066386
## [115,] 0.0050308206
## [116,] 0.0041626477
## [117,] -0.0253965791
## [118,] 0.0207869138
## [119,] 0.0043440107
## [120,] -0.0158761052
## [121,] 0.0156699333
## [122,] -0.0191884914
## [123,] -0.0149727723
## [124,] -0.0066446113
## [125,] 0.0090990246
## [126,] 0.0187605444
## [127,] -0.0082980805
## [128,] -0.0412513312
## [129,] -0.0035875216
## [130,] 0.0249161738
## [131,] -0.0074224216
## [132,] -0.0124158490
## [133,] 0.0129144954
## [134,] 0.0098229200
## [135,] 0.0074880750
## [136,] 0.0065066187
## [137,] 0.0019303201
## [138,] 0.0111105378
## [139,] 0.0150239973
## [140,] -0.0027287745
## [141,] -0.0015196991
## [142,] 0.0060173034
## [143,] -0.0050990406
## [144,] 0.0224212861
## [145,] -0.0071241875
## [146,] 0.0038148270
## [147,] -0.0049106321
## [148,] -0.0038652699
## [149,] -0.0184485449
## [150,] -0.0059056406
## [151,] -0.0171204309
## [152,] 0.0050161981
## [153,] 0.0038451590
## [154,] -0.0002077944
## [155,] -0.0103418353
## [156,] -0.0078265083
## [157,] -0.0061523772
## [158,] 0.0190827594
## [159,] -0.0111740273
## [160,] 0.0104141686
## [161,] 0.0117585585
## [162,] 0.0143510551
## [163,] 0.0014843359
## [164,] -0.0186941909
## [165,] 0.0124850801
## [166,] -0.0259382915
## [167,] -0.0146935716
## [168,] 0.0207746433
## [169,] 0.0030980461
## [170,] 0.0136724840
## [171,] -0.0100481735
## [172,] 0.0146432473
## [173,] 0.0228407297
## [174,] 0.0033491625
## [175,] -0.0156913955
## [176,] 0.0012305765
## [177,] -0.0057096863
## [178,] -0.0071656259
## [179,] 0.0195350176
## [180,] 0.0099704222
## [181,] 0.0012273109
## [182,] 0.0070060646
## [183,] -0.0278156482
## [184,] 0.0197966714
## [185,] 0.0107824365
## [186,] -0.0040862075
## [187,] 0.0048302563
## [188,] 0.0411239319
## [189,] -0.0276598662
## [190,] 0.0156765747
## [191,] -0.0077621291
## [192,] 0.0192193465
## [193,] 0.0095794285
## [194,] 0.0230249072
## [195,] 0.0098530344
## [196,] 0.0084168218
## [197,] -0.0008843606
## [198,] 0.0039782276
## [199,] 0.0218622926
## [200,] 0.0053506295
## [201,] -0.0205744681
## [202,] -0.0217580011
attributes(Laptop_pca)
## $names
## [1] "sdev" "rotation" "center" "scale" "x"
##
## $class
## [1] "prcomp"
Laptopyp_pca <- cbind(data.frame(Brand),Laptop_pca$x)
Laptopyp_pca
## Brand PC1 PC2 PC3 PC4 PC5
## 1 Asus -0.81660659 2.012406565 1.124421489 -0.085921187 0.576413679
## 2 Acer 1.73185241 1.835513200 -0.013372921 -0.440652892 0.746935751
## 3 Lenovo -1.79881923 2.177464752 -0.492917304 -0.177049265 0.050409846
## 4 Acer -0.45458727 0.274899827 1.047099540 -0.290555666 1.993366707
## 5 Acer 1.65527056 -0.882968168 1.804756280 0.829836868 0.311584112
## 6 HP -0.90476280 -0.822865513 -0.341521663 -2.301736592 0.834618971
## 7 Lenovo -1.37934003 -0.454074853 1.572723230 -1.528829785 0.661089719
## 8 Lenovo -1.60404614 0.127668702 -1.180156460 0.921204315 0.200145674
## 9 Lenovo -0.43059121 0.413560941 -1.225512202 0.595488808 -0.275397324
## 10 Acer -0.44673530 -0.601276267 1.714273823 -0.084737467 0.509502368
## 11 Asus 1.40027721 1.320959304 0.118881187 1.634721242 0.972927162
## 12 Lenovo -0.65971178 0.146403103 2.120544859 0.115433359 0.629852054
## 13 Acer -0.52236110 1.220330908 -0.728462215 0.388593612 -0.835474308
## 14 HP -1.38396046 0.239619449 -0.887094809 -0.592114084 -1.612236079
## 15 Asus -1.73511340 0.759690576 0.146944074 0.464920726 1.549021612
## 16 HP -1.71604682 -1.366501955 1.230979503 1.237829907 0.105582566
## 17 Asus -1.02430349 -0.154772678 -0.295778576 -2.529322385 0.406425352
## 18 Acer -2.02635668 -0.108688900 1.407246871 1.522869228 -0.705925269
## 19 Dell -1.70749468 0.958670764 0.797904303 -0.499394491 1.158148983
## 20 Asus -1.65936280 -0.195055585 -0.474181115 0.831695475 -0.722612651
## 21 HP 1.43141361 0.951531378 0.340618529 1.264455181 -0.817925747
## 22 Acer 1.75134947 -0.405383116 -0.136071643 1.136800838 -0.564955621
## 23 Asus 1.87787542 0.761572613 1.168280207 -1.362005319 -1.908650075
## 24 Dell 1.72095646 0.516923606 -0.002732164 0.475029533 -0.951407600
## 25 Dell -1.76992582 0.497836947 0.300990882 0.528600308 0.306395991
## 26 Lenovo 2.01303425 0.021519800 -1.285466182 0.220213820 -1.281976721
## 27 Lenovo -1.49654071 0.777809599 -1.449811745 0.011842075 -0.706615869
## 28 HP 1.63978022 1.301945390 -0.809631743 0.802707178 -0.691622622
## 29 Asus -0.53629517 1.032787095 -0.515126732 0.227679672 -0.182744086
## 30 Asus 1.20793469 2.327789538 0.564554221 1.265041390 0.200561071
## 31 Lenovo 1.88659747 -0.686299859 1.364247213 -0.260051221 -0.497967566
## 32 Asus -1.46190286 0.319750869 1.113499215 -1.489181260 -0.965607133
## 33 Asus 1.34840080 -0.535729826 1.494173752 2.101826435 -0.920296483
## 34 Dell -0.38649211 0.049626072 -0.896591096 0.647105390 -0.199119518
## 35 Lenovo -1.16239373 -1.564024155 -1.632131688 0.232293081 0.051578674
## 36 Acer -1.16310490 -0.469478334 0.079055542 -1.437491175 1.167315992
## 37 Lenovo 2.09560642 -2.032659696 0.671896383 0.204214021 -0.829406049
## 38 Acer -1.15650417 -2.250959740 0.247310337 -0.523673213 -0.682536654
## 39 Dell -1.52844851 -1.102461650 0.862825338 0.037891934 -0.576880981
## 40 HP -1.23094120 -0.580372317 -1.291398720 -0.198118781 0.858865435
## 41 Asus -1.69119259 0.526831279 0.705545116 0.050308910 1.207973390
## 42 Dell -1.58142344 -0.991268227 0.460762484 0.390253912 -1.573948931
## 43 Asus -1.70459394 -0.060206781 1.124178184 0.041306845 -0.972911740
## 44 HP -0.59011963 0.883429206 1.814075112 -0.823637762 -0.411844191
## 45 HP 2.41126489 -0.361733470 -1.088891996 -1.387753308 0.720809093
## 46 Dell -0.41485603 -0.491246501 -1.018812473 1.460602804 0.719968418
## 47 HP -1.05656263 -1.546670449 -1.595421513 -0.188638752 0.202850844
## 48 Acer -1.92774231 -0.401860171 0.107170382 2.041534076 0.353571011
## 49 HP 1.99192631 0.040523414 -0.947796819 0.161889479 -0.600347293
## 50 Asus -0.46526440 1.156362731 0.053005060 -0.486131977 -0.755470144
## 51 Asus 1.94368710 1.576081964 -0.955634539 -0.877620179 -0.830225475
## 52 Asus -0.56277774 -0.053332157 2.400973958 -0.324513981 1.478940842
## 53 Asus -1.35011266 0.882187459 -0.301458155 -1.505996069 1.008332205
## 54 Acer 1.55672048 0.392539114 1.816520335 0.305627170 -0.667604816
## 55 Lenovo 2.30501789 0.047077510 -0.601058496 -1.516862857 0.493212639
## 56 Dell -1.74052761 1.173251404 -0.623025636 0.375322872 0.543717353
## 57 Asus 2.26933790 -1.587004721 -1.339379292 0.534269512 0.832060803
## 58 HP -0.68349614 1.260295881 -0.189558236 0.849981658 1.009096978
## 59 Asus -0.20487716 -0.585950566 -1.458859069 0.559676123 -0.760268457
## 60 HP -0.22256205 -0.241983081 -0.626356331 -0.215977703 -0.965018483
## 61 HP -0.16404988 1.002547293 -1.178331307 -1.174924073 -1.175318254
## 62 Asus -1.60808144 0.862669117 -0.140122969 -0.298690513 -0.718190919
## 63 Acer 1.85078523 1.159714942 0.298070517 -0.626939432 1.126759088
## 64 HP 0.24810574 -0.712856418 -1.079125815 -1.654115226 0.641166568
## 65 HP -1.45157298 -0.489550267 -0.735092881 0.559208338 1.728050416
## 66 Asus 1.56965304 1.312849333 1.848593910 -0.597084832 -1.196334213
## 67 HP 1.71101604 0.266258616 1.904357273 -0.527245378 -0.172998957
## 68 HP -1.60037311 0.783282081 -0.219467418 -0.293456198 -0.807037786
## 69 Asus -1.70298321 -0.939577772 0.340961680 1.066529998 -2.026447508
## 70 Asus -0.31848602 -0.657073306 -0.736003753 0.710093044 0.741158426
## 71 Dell 2.01995765 -0.444464701 -1.021723145 0.308848608 -0.349005128
## 72 Acer 1.80803575 1.967613652 -0.770303005 -0.714053439 -0.832551012
## 73 Acer -1.94471258 0.963792831 -0.819406485 1.763021429 -0.005483762
## 74 HP 1.61062347 -1.405180688 2.130132707 1.357747016 1.305523356
## 75 Acer -0.52462163 0.560226291 -0.369725811 0.426353703 -1.299849952
## 76 HP 1.82142378 -1.463880284 0.729256532 1.070311147 -1.420154056
## 77 Dell -1.59449347 -0.235580947 1.442712811 -0.583821205 -0.019378131
## 78 Asus -1.64483238 -0.991561445 0.409601671 0.910142695 -1.811171853
## 79 Asus -0.22997301 -1.315697378 -0.005360192 0.236239955 -2.426027087
## 80 Asus -0.10951224 1.157032336 -0.717653912 -1.766543864 -0.237725971
## 81 Acer 1.74858680 0.053684173 0.824020656 0.422479551 1.142035089
## 82 Dell 1.64112771 -0.326043114 -0.417095962 1.985121094 0.365658012
## 83 Acer -0.98398464 -0.207585977 -0.551527639 -2.382207089 -0.111349095
## 84 Acer 0.19030298 -1.084360669 -1.306882780 -0.864716340 1.207029900
## 85 Dell -0.05417610 -2.466251068 0.376596691 0.210061311 -0.634458849
## 86 Dell -0.49856660 0.418566468 -0.367994683 0.579648533 0.568194209
## 87 Dell 2.10343096 0.470675234 -0.137568623 -1.334047375 -0.754384561
## 88 Dell 0.06069932 -0.528593073 -1.599571362 -0.646879830 0.077271964
## 89 Asus -1.50261625 0.798489316 -0.266473271 -0.470608980 1.787357870
## 90 Lenovo -1.25559099 -1.164254435 0.488242580 -1.025153113 -1.033985243
## 91 Lenovo 1.73370912 1.016559584 1.051183954 -0.551390543 0.993232208
## 92 Dell 1.70222880 0.988471761 -0.845934486 0.672767466 -1.345286514
## 93 Lenovo -0.11520108 -0.934673593 0.538604943 -0.893351627 -1.390853923
## 94 Lenovo 1.81457545 0.175300158 -0.925404578 0.764220190 -0.807724061
## 95 Dell -1.79803628 0.924105366 -0.896164109 0.997345167 0.061479340
## 96 Lenovo -0.81910650 1.337109036 -0.114531566 1.276636401 0.108093678
## 97 Acer -1.61961918 -0.197901996 -0.388056652 0.851309434 1.220918952
## 98 HP -0.30677716 -0.012289501 1.391327755 -1.346431721 -0.352637984
## 99 HP 1.52697708 1.019672964 -0.081529063 1.288196756 0.024872007
## 100 Dell -0.16971743 -0.176394886 1.042574604 -1.605383399 -0.861149577
## 101 Asus -0.17967755 -0.776613049 -1.634770722 0.738990335 -0.102558337
## 102 Dell -1.91259063 1.241183780 2.056760670 -0.409300658 -0.122977627
## 103 Asus -1.02357588 -1.476065571 0.328418024 -1.737948015 -0.920309117
## 104 HP 0.11017447 -1.529048263 -0.806341208 -0.673914837 -0.089242760
## 105 Dell 2.16596487 -0.333964045 -0.624577406 -0.541950087 0.552586120
## 106 Acer 2.22845168 0.759911769 -0.913307142 -1.614774814 0.149010639
## 107 Lenovo -1.22658424 -1.251169399 0.468757544 -0.938769035 -1.025910474
## 108 Asus 1.46929508 1.357200565 -0.606062826 1.461884839 -0.481025114
## 109 Lenovo -1.53145641 -0.302390707 -0.531366318 0.299940311 -0.617146476
## 110 Lenovo 1.23235938 2.069910397 0.462498741 1.327902034 0.210362081
## 111 Dell -0.35484954 -1.333240678 1.774856080 0.139864569 1.218659187
## 112 Lenovo -1.50667704 0.728200700 -1.051612908 -0.275262345 -0.668549391
## 113 Acer -1.45371240 -0.131268822 -0.786346346 0.034975622 -1.230740064
## 114 Lenovo -0.03522255 -1.184441362 -0.192877017 -0.473186338 0.801117871
## 115 Dell -1.22503335 -0.699439502 -0.873371181 -0.360164684 1.852543337
## 116 Acer 2.03389892 -0.574482714 1.478080226 -1.154503078 -0.152403201
## 117 HP 1.47025167 2.872824354 0.063047016 -0.026328932 -0.111518426
## 118 Lenovo -1.65203250 1.398651131 -0.099143165 -0.786841092 -0.977924145
## 119 Dell 1.68622542 1.634885623 0.194848217 -0.299259711 0.428836878
## 120 HP -1.53570767 0.957770390 -1.189411982 -0.054066244 -0.321888524
## 121 HP -0.44293184 0.870986505 -1.420550512 0.418351034 -1.035257235
## 122 Asus -1.73488293 1.234913173 0.239841605 0.019339117 1.424628584
## 123 Acer -0.26494389 -1.209574163 -0.788199807 1.273062846 1.861776949
## 124 Lenovo 1.98244614 1.516102198 -0.389564296 -1.357892233 -0.403396404
## 125 Dell -0.60441879 -1.089272039 1.603822785 1.076125904 0.444720920
## 126 Asus 1.84420815 -0.083592098 -0.348983865 0.586794950 0.630812103
## 127 Acer -1.91102358 0.476437960 1.771801091 0.306837263 -0.194329307
## 128 Asus 1.70132247 1.494646944 0.724133824 -0.233893533 1.595408527
## 129 Acer -1.54953696 0.023241468 -0.461044892 0.193908225 -0.742527212
## 130 Acer -1.31027489 0.262374587 -0.919958403 -1.153148569 -1.554929683
## 131 Lenovo -0.12536386 -2.195914392 0.466099727 0.242946014 -0.695886518
## 132 Acer -0.63280498 0.170344722 1.191074536 0.384865394 -1.340450162
## 133 Asus -0.20170707 -1.874305370 -0.094559763 0.837987822 1.300156307
## 134 Acer -0.38166433 0.379147099 1.033369321 -1.085482891 -1.488629424
## 135 Lenovo 2.07758926 -0.567298547 -1.027985948 0.199698548 -0.231644442
## 136 Lenovo 1.45958025 0.829706855 0.194769246 1.516083239 0.706638786
## 137 Asus 1.15807363 1.068164040 0.882398529 2.344272216 -0.081786260
## 138 HP -1.67955424 1.791108409 -0.844568185 -0.359585369 -0.274867039
## 139 HP 2.06594005 -0.463036778 -0.913594572 0.079699389 -0.060829806
## 140 Acer 2.04508383 -1.178592701 1.258242956 -0.551597621 -0.211993433
## 141 Dell 2.32848518 -1.121873202 -1.501921676 -0.212781477 0.277597658
## 142 Acer -0.62008738 1.208817948 -0.042756915 0.477445305 1.442545524
## 143 Asus 2.19909457 -1.318759961 -1.185252824 0.392496577 0.060378582
## 144 Asus -1.36968021 0.645603093 -0.226363254 -1.281847756 1.318064738
## 145 Asus -0.01987145 -1.030653589 -1.512858508 0.165128670 0.501163848
## 146 Asus -1.47180056 -0.508540902 -1.328253750 0.880021856 0.469285293
## 147 Asus 1.69581746 -0.528065212 0.346157173 1.357334535 0.465440970
## 148 Lenovo -0.46553567 -0.884214205 1.812958241 0.191685349 0.893928062
## 149 HP -1.25468275 -0.209745294 -0.609207115 -0.916457951 -0.579522958
## 150 Asus 2.28961543 -1.723065522 -1.457436700 0.418767815 -0.142416284
## 151 Dell -1.08140087 -0.251309666 -0.493090150 -1.787889704 -0.101032440
## 152 Dell -1.93572344 0.826387625 0.391425512 0.994656798 0.092074387
## 153 Dell -2.00219445 0.829744248 0.206909943 1.400837595 -0.381218730
## 154 Dell 1.58648723 0.219529098 0.319451631 1.223762782 -0.212252621
## 155 Lenovo 1.67729036 0.356074593 2.036671041 -0.373037641 -0.027333817
## 156 Dell -1.42443172 -1.601441962 1.227565943 -0.037614488 0.609750937
## 157 Asus -0.28373934 0.076741143 -1.789629418 0.597332341 -1.134228610
## 158 Acer -0.44937771 0.997318779 0.573678031 -0.590902657 2.246673600
## 159 Dell 2.00023152 -1.467714905 -0.087407764 0.895956575 0.519743754
## 160 Lenovo 1.69722757 2.234837697 -0.344158156 -0.598187692 -0.230204607
## 161 Lenovo 1.96892143 0.239551142 -0.308234892 -0.199238758 1.500939343
## 162 Dell 2.42080576 0.131777867 -0.743792448 -2.164962847 1.179399980
## 163 Acer 2.10156832 -0.244279176 1.466665086 -1.760588338 -0.322817955
## 164 Dell -0.36781116 -1.249966349 0.075383103 1.197834974 1.001585389
## 165 Lenovo 2.33833393 -0.949703534 -0.098634339 -1.342743864 0.579105562
## 166 HP -1.40230118 0.103625344 -0.506421729 -0.281097191 0.975478388
## 167 Asus -1.32452726 0.492049858 -0.349839074 -1.316675977 -0.574558821
## 168 Lenovo -0.09452724 -1.096714590 -0.203392649 -0.371095355 0.685330245
## 169 Dell -1.18653506 -0.500211272 -1.494219867 -0.460894648 0.443032606
## 170 Asus -0.16768800 0.141658973 -0.692746567 -0.677094272 0.451281454
## 171 Dell -0.62563131 1.053872209 0.498227005 0.219230799 0.069086052
## 172 Dell -1.23081095 -2.334429428 0.381005414 -0.112934329 -0.437117648
## 173 HP 1.44881163 1.437192599 0.515797307 0.630085148 -0.736557660
## 174 Asus -1.14667340 -0.719540803 -1.034961982 -0.653585076 1.611805312
## 175 Asus -1.68278635 0.250912369 1.489461739 -0.465084806 -0.387655581
## 176 HP -0.86080710 1.003738300 -0.500821614 2.056499864 0.319331337
## 177 Lenovo -1.63460208 0.377901361 0.305484862 -0.003277031 0.545002805
## 178 Dell -0.43063911 0.007605337 0.663941378 -0.278227678 -2.106908011
## 179 Acer 2.22740745 0.117344688 -0.746662070 -1.318956552 0.100142064
## 180 Dell 2.14067645 -1.624000757 -1.019983396 0.804505557 0.570176389
## 181 Dell 1.82869908 -0.441334486 1.992484647 -0.456995674 0.606789245
## 182 Lenovo -1.38640672 -1.060569331 -0.024153840 -0.264170245 -2.343207666
## 183 Dell -0.48078134 1.270437461 -0.884062705 0.255020335 -0.273322596
## 184 HP 1.80140311 -0.212104543 2.068284861 -0.650690520 0.610362190
## 185 HP 0.03095186 -1.365586330 -1.375392002 0.062043870 1.103516590
## 186 Asus -0.55364299 0.679436011 0.617935783 0.115087809 0.666889883
## 187 Acer 2.05522582 -0.566735472 -1.532078975 0.623879004 -0.467312215
## 188 Dell 1.85017057 -1.270750811 0.443950989 0.599579844 -2.040442623
## 189 Dell -0.33778950 -1.913541477 1.336323254 0.787037132 0.684349093
## 190 Lenovo 1.84788409 0.920015841 0.826512633 -0.970764542 0.724122372
## 191 HP -0.66410086 -0.546147290 1.230792569 1.130594913 -0.805906877
## 192 Acer -0.47034357 -0.064839531 1.163460564 -0.358631394 -1.004464792
## 193 Asus 2.15349719 -1.377445771 -0.940260411 0.493282640 0.588724679
## 194 HP -1.95819519 1.124305195 -0.462565672 1.289174556 -0.189522430
## 195 Asus 1.39434305 0.249962886 0.519159784 2.010119835 -0.017619254
## 196 Lenovo -1.52469345 0.285165815 -0.743342512 0.177392492 1.124918798
## 197 Lenovo -0.34507636 0.607015633 -1.056688598 0.010282930 -0.861818418
## 198 Dell -0.58359405 2.041321848 -0.472975595 -0.249350917 0.011259423
## 199 Acer -1.24625865 -2.172700311 0.590972421 -0.302468439 -0.106771861
## 200 Asus 0.21234955 -0.908062566 -1.118975759 -1.406462486 0.679971781
## 201 HP -1.55058112 -0.421675837 0.582679308 0.250031356 1.744486673
## 202 Lenovo -0.93820823 -2.063104605 -0.965851663 -0.678396573 0.268367663
## PC6
## 1 0.0181156855
## 2 -0.0114349045
## 3 -0.0045004865
## 4 0.0151211509
## 5 0.0078520147
## 6 -0.0004311798
## 7 0.0148484176
## 8 0.0016018473
## 9 0.0323505533
## 10 -0.0087817779
## 11 -0.0197518929
## 12 -0.0042411506
## 13 -0.0361282842
## 14 -0.0125128964
## 15 -0.0167227895
## 16 -0.0170862585
## 17 0.0403771733
## 18 -0.0048718924
## 19 0.0218983665
## 20 0.0161757967
## 21 0.0133301330
## 22 0.0022490334
## 23 -0.0104293245
## 24 -0.0087565409
## 25 0.0003284463
## 26 -0.0151839239
## 27 -0.0145836649
## 28 -0.0100193504
## 29 0.0239650067
## 30 0.0100951356
## 31 -0.0004354867
## 32 -0.0099278759
## 33 0.0197859578
## 34 -0.0022681797
## 35 0.0203360392
## 36 -0.0152161040
## 37 -0.0049268188
## 38 0.0197133219
## 39 0.0208419520
## 40 -0.0079565331
## 41 -0.0194345596
## 42 0.0160550093
## 43 -0.0107721804
## 44 0.0098734495
## 45 -0.0156719744
## 46 -0.0125660687
## 47 -0.0052329723
## 48 0.0271504689
## 49 -0.0138073548
## 50 -0.0085590069
## 51 -0.0097478653
## 52 0.0003463403
## 53 0.0126435300
## 54 -0.0155290746
## 55 -0.0160873510
## 56 0.0148809245
## 57 -0.0234726983
## 58 -0.0028437686
## 59 -0.0054560766
## 60 0.0003662338
## 61 -0.0019385015
## 62 -0.0213126312
## 63 -0.0164646701
## 64 -0.0175098641
## 65 -0.0037894514
## 66 -0.0126925534
## 67 0.0134153160
## 68 -0.0097143569
## 69 0.0016162875
## 70 0.0288425293
## 71 0.0199816720
## 72 0.0065775045
## 73 -0.0079136664
## 74 0.0115551990
## 75 0.0068629583
## 76 -0.0128121950
## 77 0.0100829313
## 78 -0.0203604491
## 79 -0.0192588759
## 80 -0.0023722256
## 81 -0.0115563773
## 82 -0.0117758604
## 83 0.0023973549
## 84 -0.0154711038
## 85 -0.0157841361
## 86 0.0128805691
## 87 -0.0046601789
## 88 -0.0055509745
## 89 -0.0128760887
## 90 0.0065673093
## 91 0.0089941544
## 92 -0.0062238876
## 93 -0.0182543821
## 94 0.0142195350
## 95 0.0135074119
## 96 0.0066943169
## 97 0.0044519258
## 98 0.0274719371
## 99 -0.0244344798
## 100 0.0023465561
## 101 0.0005884054
## 102 -0.0214409268
## 103 -0.0109776503
## 104 0.0056939497
## 105 -0.0052014908
## 106 -0.0026188085
## 107 -0.0217147822
## 108 -0.0005424435
## 109 0.0200321753
## 110 0.0269124539
## 111 -0.0198908073
## 112 0.0095217615
## 113 -0.0120873633
## 114 -0.0021066386
## 115 0.0050308206
## 116 0.0041626477
## 117 -0.0253965791
## 118 0.0207869138
## 119 0.0043440107
## 120 -0.0158761052
## 121 0.0156699333
## 122 -0.0191884914
## 123 -0.0149727723
## 124 -0.0066446113
## 125 0.0090990246
## 126 0.0187605444
## 127 -0.0082980805
## 128 -0.0412513312
## 129 -0.0035875216
## 130 0.0249161738
## 131 -0.0074224216
## 132 -0.0124158490
## 133 0.0129144954
## 134 0.0098229200
## 135 0.0074880750
## 136 0.0065066187
## 137 0.0019303201
## 138 0.0111105378
## 139 0.0150239973
## 140 -0.0027287745
## 141 -0.0015196991
## 142 0.0060173034
## 143 -0.0050990406
## 144 0.0224212861
## 145 -0.0071241875
## 146 0.0038148270
## 147 -0.0049106321
## 148 -0.0038652699
## 149 -0.0184485449
## 150 -0.0059056406
## 151 -0.0171204309
## 152 0.0050161981
## 153 0.0038451590
## 154 -0.0002077944
## 155 -0.0103418353
## 156 -0.0078265083
## 157 -0.0061523772
## 158 0.0190827594
## 159 -0.0111740273
## 160 0.0104141686
## 161 0.0117585585
## 162 0.0143510551
## 163 0.0014843359
## 164 -0.0186941909
## 165 0.0124850801
## 166 -0.0259382915
## 167 -0.0146935716
## 168 0.0207746433
## 169 0.0030980461
## 170 0.0136724840
## 171 -0.0100481735
## 172 0.0146432473
## 173 0.0228407297
## 174 0.0033491625
## 175 -0.0156913955
## 176 0.0012305765
## 177 -0.0057096863
## 178 -0.0071656259
## 179 0.0195350176
## 180 0.0099704222
## 181 0.0012273109
## 182 0.0070060646
## 183 -0.0278156482
## 184 0.0197966714
## 185 0.0107824365
## 186 -0.0040862075
## 187 0.0048302563
## 188 0.0411239319
## 189 -0.0276598662
## 190 0.0156765747
## 191 -0.0077621291
## 192 0.0192193465
## 193 0.0095794285
## 194 0.0230249072
## 195 0.0098530344
## 196 0.0084168218
## 197 -0.0008843606
## 198 0.0039782276
## 199 0.0218622926
## 200 0.0053506295
## 201 -0.0205744681
## 202 -0.0217580011
tabmeansPC <- aggregate(Laptopyp_pca[,2:6],by=list(Brand=Laptop$Brand),mean)
tabmeansPC
## Brand PC1 PC2 PC3 PC4 PC5
## 1 Acer 0.05344949 0.00195327 0.23885291 -0.11868560 0.02933522
## 2 Asus -0.07661954 0.10404238 -0.07685442 0.07116492 0.04588456
## 3 Dell -0.04121503 -0.20325400 0.05648158 0.14467811 0.03308683
## 4 HP -0.03722286 0.11553968 -0.15829846 0.02340323 -0.02910122
## 5 Lenovo 0.13006435 -0.01547107 -0.04112635 -0.16521248 -0.09682897
tabmeansPC <- tabmeansPC[rev(order(tabmeansPC$Brand)),]
tabmeansPC
## Brand PC1 PC2 PC3 PC4 PC5
## 5 Lenovo 0.13006435 -0.01547107 -0.04112635 -0.16521248 -0.09682897
## 4 HP -0.03722286 0.11553968 -0.15829846 0.02340323 -0.02910122
## 3 Dell -0.04121503 -0.20325400 0.05648158 0.14467811 0.03308683
## 2 Asus -0.07661954 0.10404238 -0.07685442 0.07116492 0.04588456
## 1 Acer 0.05344949 0.00195327 0.23885291 -0.11868560 0.02933522
tabfmeans <- t(tabmeansPC[,-1])
tabfmeans
## 5 4 3 2 1
## PC1 0.13006435 -0.03722286 -0.04121503 -0.07661954 0.05344949
## PC2 -0.01547107 0.11553968 -0.20325400 0.10404238 0.00195327
## PC3 -0.04112635 -0.15829846 0.05648158 -0.07685442 0.23885291
## PC4 -0.16521248 0.02340323 0.14467811 0.07116492 -0.11868560
## PC5 -0.09682897 -0.02910122 0.03308683 0.04588456 0.02933522
colnames(tabfmeans) <- t(as.vector(tabmeansPC[1]$Brand))
tabfmeans
## Lenovo HP Dell Asus Acer
## PC1 0.13006435 -0.03722286 -0.04121503 -0.07661954 0.05344949
## PC2 -0.01547107 0.11553968 -0.20325400 0.10404238 0.00195327
## PC3 -0.04112635 -0.15829846 0.05648158 -0.07685442 0.23885291
## PC4 -0.16521248 0.02340323 0.14467811 0.07116492 -0.11868560
## PC5 -0.09682897 -0.02910122 0.03308683 0.04588456 0.02933522
tabsdsPC <- aggregate(Laptopyp_pca[,2:6],by=list(Brand=Laptop$Brand),sd)
tabfsds <- t(tabsdsPC[,-1])
colnames(tabfsds) <- t(as.vector(tabsdsPC[1]$Brand))
tabfsds
## Acer Asus Dell HP Lenovo
## PC1 1.507152 1.387584 1.5030853 1.3917193 1.5113413
## PC2 0.947107 1.055141 1.0908086 1.0700141 1.1709542
## PC3 1.001354 0.982372 0.9712039 1.0836630 0.9870737
## PC4 1.028600 1.085522 0.8792446 0.9838256 0.7594522
## PC5 1.031793 1.050287 0.8343943 0.8624507 0.8318051
#2 Explain the variate representation each PCs
#Ans In PC1 Processor_Speed has a moderate negative loading.RAM_Size has a small negative loading. Storage_Capacity has a large positive loading. Screen_Size has a small negative loading. Weight has a small positive loading. Price has a large positive loading. This component seems to capture laptops with high storage capacity and price, with some influence from processor speed and weight.Lenovo has the highest mean score on PC1, indicating that laptops from Lenovo might be perceived as offering good performance and value for their price. In PC2 Processor_Speed has a moderate positive loading. RAM_Size has a large negative loading. Storage_Capacity has a small positive loading. Screen_Size has a large negative loading. Weight has a large negative loading. Price has a small positive loading. This component seems to capture laptops with lower RAM size, screen size, and weight, but higher processor speed.HP has the highest mean score on PC2, suggesting that HP laptops might be perceived as offering a good balance between performance and portability. In PC3 Processor_Speed has a large positive loading. RAM_Size has a large positive loading. Storage_Capacity has a small positive loading. Screen_Size has a moderate negative loading. Weight has a small positive loading. Price has a small positive loading. This component seems to capture laptops with higher RAM size and processor speed, but lower screen size.Dell has the highest mean score on PC3, indicating that Dell laptops might be perceived as offering larger screen sizes and possibly catering to multimedia or gaming. In PC4 Processor_Speed has a large positive loading. RAM_Size has a small negative loading. Storage_Capacity has a small positive loading. Screen_Size has a moderate positive loading. Weight has a small negative loading. Price has a small positive loading. This component seems to capture laptops with higher processor speed and screen size, but lower RAM size.Asus has the highest mean score on PC4, suggesting that Asus laptops might be perceived as offering good performance but at a higher price point. In PC5 Processor_Speed has a moderate positive loading. RAM_Size has a small negative loading. Storage_Capacity has a small negative loading. Screen_Size has a small negative loading. Weight has a moderate positive loading. Price has a moderate negative loading. This component seems to capture laptops with higher weight and lower price, with some influence from processor speed.cer has the highest mean score on PC5, indicating that Acer laptops might be perceived as more lightweight and portable.
#3 Perform some visualization using PCs
plot(eigen_Laptop, xlab = "Component number", ylab = "Component variance", type = "l", main = "Scree diagram")
#Ans) From the above graph, we can stop at any of the sharp edges, according to my analysis above, I have decided to retain only till PC3, to balance between capturing a substantial portion of the variance
plot(log(eigen_Laptop), xlab = "Component number",ylab = "log(Component variance)", type="l",main = "Log(eigenvalue) diagram")
#Ans) From the above graph, we can stop at any of the sharp edges, according to my analysis above, I have decided to retain only till PC3, to balance between capturing a substantial portion of the variance
plot(Laptop_pca)
#The above graph shows us the variance against the principle components
diag(cov(Laptop_pca$x))
## PC1 PC2 PC3 PC4 PC5 PC6
## 2.0909019711 1.1363696945 1.0031407664 0.9153754298 0.8539941999 0.0002179382
xlim <- range(Laptop_pca$x[,1])
Laptop_pca$x[,1]
## [1] -0.81660659 1.73185241 -1.79881923 -0.45458727 1.65527056 -0.90476280
## [7] -1.37934003 -1.60404614 -0.43059121 -0.44673530 1.40027721 -0.65971178
## [13] -0.52236110 -1.38396046 -1.73511340 -1.71604682 -1.02430349 -2.02635668
## [19] -1.70749468 -1.65936280 1.43141361 1.75134947 1.87787542 1.72095646
## [25] -1.76992582 2.01303425 -1.49654071 1.63978022 -0.53629517 1.20793469
## [31] 1.88659747 -1.46190286 1.34840080 -0.38649211 -1.16239373 -1.16310490
## [37] 2.09560642 -1.15650417 -1.52844851 -1.23094120 -1.69119259 -1.58142344
## [43] -1.70459394 -0.59011963 2.41126489 -0.41485603 -1.05656263 -1.92774231
## [49] 1.99192631 -0.46526440 1.94368710 -0.56277774 -1.35011266 1.55672048
## [55] 2.30501789 -1.74052761 2.26933790 -0.68349614 -0.20487716 -0.22256205
## [61] -0.16404988 -1.60808144 1.85078523 0.24810574 -1.45157298 1.56965304
## [67] 1.71101604 -1.60037311 -1.70298321 -0.31848602 2.01995765 1.80803575
## [73] -1.94471258 1.61062347 -0.52462163 1.82142378 -1.59449347 -1.64483238
## [79] -0.22997301 -0.10951224 1.74858680 1.64112771 -0.98398464 0.19030298
## [85] -0.05417610 -0.49856660 2.10343096 0.06069932 -1.50261625 -1.25559099
## [91] 1.73370912 1.70222880 -0.11520108 1.81457545 -1.79803628 -0.81910650
## [97] -1.61961918 -0.30677716 1.52697708 -0.16971743 -0.17967755 -1.91259063
## [103] -1.02357588 0.11017447 2.16596487 2.22845168 -1.22658424 1.46929508
## [109] -1.53145641 1.23235938 -0.35484954 -1.50667704 -1.45371240 -0.03522255
## [115] -1.22503335 2.03389892 1.47025167 -1.65203250 1.68622542 -1.53570767
## [121] -0.44293184 -1.73488293 -0.26494389 1.98244614 -0.60441879 1.84420815
## [127] -1.91102358 1.70132247 -1.54953696 -1.31027489 -0.12536386 -0.63280498
## [133] -0.20170707 -0.38166433 2.07758926 1.45958025 1.15807363 -1.67955424
## [139] 2.06594005 2.04508383 2.32848518 -0.62008738 2.19909457 -1.36968021
## [145] -0.01987145 -1.47180056 1.69581746 -0.46553567 -1.25468275 2.28961543
## [151] -1.08140087 -1.93572344 -2.00219445 1.58648723 1.67729036 -1.42443172
## [157] -0.28373934 -0.44937771 2.00023152 1.69722757 1.96892143 2.42080576
## [163] 2.10156832 -0.36781116 2.33833393 -1.40230118 -1.32452726 -0.09452724
## [169] -1.18653506 -0.16768800 -0.62563131 -1.23081095 1.44881163 -1.14667340
## [175] -1.68278635 -0.86080710 -1.63460208 -0.43063911 2.22740745 2.14067645
## [181] 1.82869908 -1.38640672 -0.48078134 1.80140311 0.03095186 -0.55364299
## [187] 2.05522582 1.85017057 -0.33778950 1.84788409 -0.66410086 -0.47034357
## [193] 2.15349719 -1.95819519 1.39434305 -1.52469345 -0.34507636 -0.58359405
## [199] -1.24625865 0.21234955 -1.55058112 -0.93820823
Laptop_pca$x
## PC1 PC2 PC3 PC4 PC5
## [1,] -0.81660659 2.012406565 1.124421489 -0.085921187 0.576413679
## [2,] 1.73185241 1.835513200 -0.013372921 -0.440652892 0.746935751
## [3,] -1.79881923 2.177464752 -0.492917304 -0.177049265 0.050409846
## [4,] -0.45458727 0.274899827 1.047099540 -0.290555666 1.993366707
## [5,] 1.65527056 -0.882968168 1.804756280 0.829836868 0.311584112
## [6,] -0.90476280 -0.822865513 -0.341521663 -2.301736592 0.834618971
## [7,] -1.37934003 -0.454074853 1.572723230 -1.528829785 0.661089719
## [8,] -1.60404614 0.127668702 -1.180156460 0.921204315 0.200145674
## [9,] -0.43059121 0.413560941 -1.225512202 0.595488808 -0.275397324
## [10,] -0.44673530 -0.601276267 1.714273823 -0.084737467 0.509502368
## [11,] 1.40027721 1.320959304 0.118881187 1.634721242 0.972927162
## [12,] -0.65971178 0.146403103 2.120544859 0.115433359 0.629852054
## [13,] -0.52236110 1.220330908 -0.728462215 0.388593612 -0.835474308
## [14,] -1.38396046 0.239619449 -0.887094809 -0.592114084 -1.612236079
## [15,] -1.73511340 0.759690576 0.146944074 0.464920726 1.549021612
## [16,] -1.71604682 -1.366501955 1.230979503 1.237829907 0.105582566
## [17,] -1.02430349 -0.154772678 -0.295778576 -2.529322385 0.406425352
## [18,] -2.02635668 -0.108688900 1.407246871 1.522869228 -0.705925269
## [19,] -1.70749468 0.958670764 0.797904303 -0.499394491 1.158148983
## [20,] -1.65936280 -0.195055585 -0.474181115 0.831695475 -0.722612651
## [21,] 1.43141361 0.951531378 0.340618529 1.264455181 -0.817925747
## [22,] 1.75134947 -0.405383116 -0.136071643 1.136800838 -0.564955621
## [23,] 1.87787542 0.761572613 1.168280207 -1.362005319 -1.908650075
## [24,] 1.72095646 0.516923606 -0.002732164 0.475029533 -0.951407600
## [25,] -1.76992582 0.497836947 0.300990882 0.528600308 0.306395991
## [26,] 2.01303425 0.021519800 -1.285466182 0.220213820 -1.281976721
## [27,] -1.49654071 0.777809599 -1.449811745 0.011842075 -0.706615869
## [28,] 1.63978022 1.301945390 -0.809631743 0.802707178 -0.691622622
## [29,] -0.53629517 1.032787095 -0.515126732 0.227679672 -0.182744086
## [30,] 1.20793469 2.327789538 0.564554221 1.265041390 0.200561071
## [31,] 1.88659747 -0.686299859 1.364247213 -0.260051221 -0.497967566
## [32,] -1.46190286 0.319750869 1.113499215 -1.489181260 -0.965607133
## [33,] 1.34840080 -0.535729826 1.494173752 2.101826435 -0.920296483
## [34,] -0.38649211 0.049626072 -0.896591096 0.647105390 -0.199119518
## [35,] -1.16239373 -1.564024155 -1.632131688 0.232293081 0.051578674
## [36,] -1.16310490 -0.469478334 0.079055542 -1.437491175 1.167315992
## [37,] 2.09560642 -2.032659696 0.671896383 0.204214021 -0.829406049
## [38,] -1.15650417 -2.250959740 0.247310337 -0.523673213 -0.682536654
## [39,] -1.52844851 -1.102461650 0.862825338 0.037891934 -0.576880981
## [40,] -1.23094120 -0.580372317 -1.291398720 -0.198118781 0.858865435
## [41,] -1.69119259 0.526831279 0.705545116 0.050308910 1.207973390
## [42,] -1.58142344 -0.991268227 0.460762484 0.390253912 -1.573948931
## [43,] -1.70459394 -0.060206781 1.124178184 0.041306845 -0.972911740
## [44,] -0.59011963 0.883429206 1.814075112 -0.823637762 -0.411844191
## [45,] 2.41126489 -0.361733470 -1.088891996 -1.387753308 0.720809093
## [46,] -0.41485603 -0.491246501 -1.018812473 1.460602804 0.719968418
## [47,] -1.05656263 -1.546670449 -1.595421513 -0.188638752 0.202850844
## [48,] -1.92774231 -0.401860171 0.107170382 2.041534076 0.353571011
## [49,] 1.99192631 0.040523414 -0.947796819 0.161889479 -0.600347293
## [50,] -0.46526440 1.156362731 0.053005060 -0.486131977 -0.755470144
## [51,] 1.94368710 1.576081964 -0.955634539 -0.877620179 -0.830225475
## [52,] -0.56277774 -0.053332157 2.400973958 -0.324513981 1.478940842
## [53,] -1.35011266 0.882187459 -0.301458155 -1.505996069 1.008332205
## [54,] 1.55672048 0.392539114 1.816520335 0.305627170 -0.667604816
## [55,] 2.30501789 0.047077510 -0.601058496 -1.516862857 0.493212639
## [56,] -1.74052761 1.173251404 -0.623025636 0.375322872 0.543717353
## [57,] 2.26933790 -1.587004721 -1.339379292 0.534269512 0.832060803
## [58,] -0.68349614 1.260295881 -0.189558236 0.849981658 1.009096978
## [59,] -0.20487716 -0.585950566 -1.458859069 0.559676123 -0.760268457
## [60,] -0.22256205 -0.241983081 -0.626356331 -0.215977703 -0.965018483
## [61,] -0.16404988 1.002547293 -1.178331307 -1.174924073 -1.175318254
## [62,] -1.60808144 0.862669117 -0.140122969 -0.298690513 -0.718190919
## [63,] 1.85078523 1.159714942 0.298070517 -0.626939432 1.126759088
## [64,] 0.24810574 -0.712856418 -1.079125815 -1.654115226 0.641166568
## [65,] -1.45157298 -0.489550267 -0.735092881 0.559208338 1.728050416
## [66,] 1.56965304 1.312849333 1.848593910 -0.597084832 -1.196334213
## [67,] 1.71101604 0.266258616 1.904357273 -0.527245378 -0.172998957
## [68,] -1.60037311 0.783282081 -0.219467418 -0.293456198 -0.807037786
## [69,] -1.70298321 -0.939577772 0.340961680 1.066529998 -2.026447508
## [70,] -0.31848602 -0.657073306 -0.736003753 0.710093044 0.741158426
## [71,] 2.01995765 -0.444464701 -1.021723145 0.308848608 -0.349005128
## [72,] 1.80803575 1.967613652 -0.770303005 -0.714053439 -0.832551012
## [73,] -1.94471258 0.963792831 -0.819406485 1.763021429 -0.005483762
## [74,] 1.61062347 -1.405180688 2.130132707 1.357747016 1.305523356
## [75,] -0.52462163 0.560226291 -0.369725811 0.426353703 -1.299849952
## [76,] 1.82142378 -1.463880284 0.729256532 1.070311147 -1.420154056
## [77,] -1.59449347 -0.235580947 1.442712811 -0.583821205 -0.019378131
## [78,] -1.64483238 -0.991561445 0.409601671 0.910142695 -1.811171853
## [79,] -0.22997301 -1.315697378 -0.005360192 0.236239955 -2.426027087
## [80,] -0.10951224 1.157032336 -0.717653912 -1.766543864 -0.237725971
## [81,] 1.74858680 0.053684173 0.824020656 0.422479551 1.142035089
## [82,] 1.64112771 -0.326043114 -0.417095962 1.985121094 0.365658012
## [83,] -0.98398464 -0.207585977 -0.551527639 -2.382207089 -0.111349095
## [84,] 0.19030298 -1.084360669 -1.306882780 -0.864716340 1.207029900
## [85,] -0.05417610 -2.466251068 0.376596691 0.210061311 -0.634458849
## [86,] -0.49856660 0.418566468 -0.367994683 0.579648533 0.568194209
## [87,] 2.10343096 0.470675234 -0.137568623 -1.334047375 -0.754384561
## [88,] 0.06069932 -0.528593073 -1.599571362 -0.646879830 0.077271964
## [89,] -1.50261625 0.798489316 -0.266473271 -0.470608980 1.787357870
## [90,] -1.25559099 -1.164254435 0.488242580 -1.025153113 -1.033985243
## [91,] 1.73370912 1.016559584 1.051183954 -0.551390543 0.993232208
## [92,] 1.70222880 0.988471761 -0.845934486 0.672767466 -1.345286514
## [93,] -0.11520108 -0.934673593 0.538604943 -0.893351627 -1.390853923
## [94,] 1.81457545 0.175300158 -0.925404578 0.764220190 -0.807724061
## [95,] -1.79803628 0.924105366 -0.896164109 0.997345167 0.061479340
## [96,] -0.81910650 1.337109036 -0.114531566 1.276636401 0.108093678
## [97,] -1.61961918 -0.197901996 -0.388056652 0.851309434 1.220918952
## [98,] -0.30677716 -0.012289501 1.391327755 -1.346431721 -0.352637984
## [99,] 1.52697708 1.019672964 -0.081529063 1.288196756 0.024872007
## [100,] -0.16971743 -0.176394886 1.042574604 -1.605383399 -0.861149577
## [101,] -0.17967755 -0.776613049 -1.634770722 0.738990335 -0.102558337
## [102,] -1.91259063 1.241183780 2.056760670 -0.409300658 -0.122977627
## [103,] -1.02357588 -1.476065571 0.328418024 -1.737948015 -0.920309117
## [104,] 0.11017447 -1.529048263 -0.806341208 -0.673914837 -0.089242760
## [105,] 2.16596487 -0.333964045 -0.624577406 -0.541950087 0.552586120
## [106,] 2.22845168 0.759911769 -0.913307142 -1.614774814 0.149010639
## [107,] -1.22658424 -1.251169399 0.468757544 -0.938769035 -1.025910474
## [108,] 1.46929508 1.357200565 -0.606062826 1.461884839 -0.481025114
## [109,] -1.53145641 -0.302390707 -0.531366318 0.299940311 -0.617146476
## [110,] 1.23235938 2.069910397 0.462498741 1.327902034 0.210362081
## [111,] -0.35484954 -1.333240678 1.774856080 0.139864569 1.218659187
## [112,] -1.50667704 0.728200700 -1.051612908 -0.275262345 -0.668549391
## [113,] -1.45371240 -0.131268822 -0.786346346 0.034975622 -1.230740064
## [114,] -0.03522255 -1.184441362 -0.192877017 -0.473186338 0.801117871
## [115,] -1.22503335 -0.699439502 -0.873371181 -0.360164684 1.852543337
## [116,] 2.03389892 -0.574482714 1.478080226 -1.154503078 -0.152403201
## [117,] 1.47025167 2.872824354 0.063047016 -0.026328932 -0.111518426
## [118,] -1.65203250 1.398651131 -0.099143165 -0.786841092 -0.977924145
## [119,] 1.68622542 1.634885623 0.194848217 -0.299259711 0.428836878
## [120,] -1.53570767 0.957770390 -1.189411982 -0.054066244 -0.321888524
## [121,] -0.44293184 0.870986505 -1.420550512 0.418351034 -1.035257235
## [122,] -1.73488293 1.234913173 0.239841605 0.019339117 1.424628584
## [123,] -0.26494389 -1.209574163 -0.788199807 1.273062846 1.861776949
## [124,] 1.98244614 1.516102198 -0.389564296 -1.357892233 -0.403396404
## [125,] -0.60441879 -1.089272039 1.603822785 1.076125904 0.444720920
## [126,] 1.84420815 -0.083592098 -0.348983865 0.586794950 0.630812103
## [127,] -1.91102358 0.476437960 1.771801091 0.306837263 -0.194329307
## [128,] 1.70132247 1.494646944 0.724133824 -0.233893533 1.595408527
## [129,] -1.54953696 0.023241468 -0.461044892 0.193908225 -0.742527212
## [130,] -1.31027489 0.262374587 -0.919958403 -1.153148569 -1.554929683
## [131,] -0.12536386 -2.195914392 0.466099727 0.242946014 -0.695886518
## [132,] -0.63280498 0.170344722 1.191074536 0.384865394 -1.340450162
## [133,] -0.20170707 -1.874305370 -0.094559763 0.837987822 1.300156307
## [134,] -0.38166433 0.379147099 1.033369321 -1.085482891 -1.488629424
## [135,] 2.07758926 -0.567298547 -1.027985948 0.199698548 -0.231644442
## [136,] 1.45958025 0.829706855 0.194769246 1.516083239 0.706638786
## [137,] 1.15807363 1.068164040 0.882398529 2.344272216 -0.081786260
## [138,] -1.67955424 1.791108409 -0.844568185 -0.359585369 -0.274867039
## [139,] 2.06594005 -0.463036778 -0.913594572 0.079699389 -0.060829806
## [140,] 2.04508383 -1.178592701 1.258242956 -0.551597621 -0.211993433
## [141,] 2.32848518 -1.121873202 -1.501921676 -0.212781477 0.277597658
## [142,] -0.62008738 1.208817948 -0.042756915 0.477445305 1.442545524
## [143,] 2.19909457 -1.318759961 -1.185252824 0.392496577 0.060378582
## [144,] -1.36968021 0.645603093 -0.226363254 -1.281847756 1.318064738
## [145,] -0.01987145 -1.030653589 -1.512858508 0.165128670 0.501163848
## [146,] -1.47180056 -0.508540902 -1.328253750 0.880021856 0.469285293
## [147,] 1.69581746 -0.528065212 0.346157173 1.357334535 0.465440970
## [148,] -0.46553567 -0.884214205 1.812958241 0.191685349 0.893928062
## [149,] -1.25468275 -0.209745294 -0.609207115 -0.916457951 -0.579522958
## [150,] 2.28961543 -1.723065522 -1.457436700 0.418767815 -0.142416284
## [151,] -1.08140087 -0.251309666 -0.493090150 -1.787889704 -0.101032440
## [152,] -1.93572344 0.826387625 0.391425512 0.994656798 0.092074387
## [153,] -2.00219445 0.829744248 0.206909943 1.400837595 -0.381218730
## [154,] 1.58648723 0.219529098 0.319451631 1.223762782 -0.212252621
## [155,] 1.67729036 0.356074593 2.036671041 -0.373037641 -0.027333817
## [156,] -1.42443172 -1.601441962 1.227565943 -0.037614488 0.609750937
## [157,] -0.28373934 0.076741143 -1.789629418 0.597332341 -1.134228610
## [158,] -0.44937771 0.997318779 0.573678031 -0.590902657 2.246673600
## [159,] 2.00023152 -1.467714905 -0.087407764 0.895956575 0.519743754
## [160,] 1.69722757 2.234837697 -0.344158156 -0.598187692 -0.230204607
## [161,] 1.96892143 0.239551142 -0.308234892 -0.199238758 1.500939343
## [162,] 2.42080576 0.131777867 -0.743792448 -2.164962847 1.179399980
## [163,] 2.10156832 -0.244279176 1.466665086 -1.760588338 -0.322817955
## [164,] -0.36781116 -1.249966349 0.075383103 1.197834974 1.001585389
## [165,] 2.33833393 -0.949703534 -0.098634339 -1.342743864 0.579105562
## [166,] -1.40230118 0.103625344 -0.506421729 -0.281097191 0.975478388
## [167,] -1.32452726 0.492049858 -0.349839074 -1.316675977 -0.574558821
## [168,] -0.09452724 -1.096714590 -0.203392649 -0.371095355 0.685330245
## [169,] -1.18653506 -0.500211272 -1.494219867 -0.460894648 0.443032606
## [170,] -0.16768800 0.141658973 -0.692746567 -0.677094272 0.451281454
## [171,] -0.62563131 1.053872209 0.498227005 0.219230799 0.069086052
## [172,] -1.23081095 -2.334429428 0.381005414 -0.112934329 -0.437117648
## [173,] 1.44881163 1.437192599 0.515797307 0.630085148 -0.736557660
## [174,] -1.14667340 -0.719540803 -1.034961982 -0.653585076 1.611805312
## [175,] -1.68278635 0.250912369 1.489461739 -0.465084806 -0.387655581
## [176,] -0.86080710 1.003738300 -0.500821614 2.056499864 0.319331337
## [177,] -1.63460208 0.377901361 0.305484862 -0.003277031 0.545002805
## [178,] -0.43063911 0.007605337 0.663941378 -0.278227678 -2.106908011
## [179,] 2.22740745 0.117344688 -0.746662070 -1.318956552 0.100142064
## [180,] 2.14067645 -1.624000757 -1.019983396 0.804505557 0.570176389
## [181,] 1.82869908 -0.441334486 1.992484647 -0.456995674 0.606789245
## [182,] -1.38640672 -1.060569331 -0.024153840 -0.264170245 -2.343207666
## [183,] -0.48078134 1.270437461 -0.884062705 0.255020335 -0.273322596
## [184,] 1.80140311 -0.212104543 2.068284861 -0.650690520 0.610362190
## [185,] 0.03095186 -1.365586330 -1.375392002 0.062043870 1.103516590
## [186,] -0.55364299 0.679436011 0.617935783 0.115087809 0.666889883
## [187,] 2.05522582 -0.566735472 -1.532078975 0.623879004 -0.467312215
## [188,] 1.85017057 -1.270750811 0.443950989 0.599579844 -2.040442623
## [189,] -0.33778950 -1.913541477 1.336323254 0.787037132 0.684349093
## [190,] 1.84788409 0.920015841 0.826512633 -0.970764542 0.724122372
## [191,] -0.66410086 -0.546147290 1.230792569 1.130594913 -0.805906877
## [192,] -0.47034357 -0.064839531 1.163460564 -0.358631394 -1.004464792
## [193,] 2.15349719 -1.377445771 -0.940260411 0.493282640 0.588724679
## [194,] -1.95819519 1.124305195 -0.462565672 1.289174556 -0.189522430
## [195,] 1.39434305 0.249962886 0.519159784 2.010119835 -0.017619254
## [196,] -1.52469345 0.285165815 -0.743342512 0.177392492 1.124918798
## [197,] -0.34507636 0.607015633 -1.056688598 0.010282930 -0.861818418
## [198,] -0.58359405 2.041321848 -0.472975595 -0.249350917 0.011259423
## [199,] -1.24625865 -2.172700311 0.590972421 -0.302468439 -0.106771861
## [200,] 0.21234955 -0.908062566 -1.118975759 -1.406462486 0.679971781
## [201,] -1.55058112 -0.421675837 0.582679308 0.250031356 1.744486673
## [202,] -0.93820823 -2.063104605 -0.965851663 -0.678396573 0.268367663
## PC6
## [1,] 0.0181156855
## [2,] -0.0114349045
## [3,] -0.0045004865
## [4,] 0.0151211509
## [5,] 0.0078520147
## [6,] -0.0004311798
## [7,] 0.0148484176
## [8,] 0.0016018473
## [9,] 0.0323505533
## [10,] -0.0087817779
## [11,] -0.0197518929
## [12,] -0.0042411506
## [13,] -0.0361282842
## [14,] -0.0125128964
## [15,] -0.0167227895
## [16,] -0.0170862585
## [17,] 0.0403771733
## [18,] -0.0048718924
## [19,] 0.0218983665
## [20,] 0.0161757967
## [21,] 0.0133301330
## [22,] 0.0022490334
## [23,] -0.0104293245
## [24,] -0.0087565409
## [25,] 0.0003284463
## [26,] -0.0151839239
## [27,] -0.0145836649
## [28,] -0.0100193504
## [29,] 0.0239650067
## [30,] 0.0100951356
## [31,] -0.0004354867
## [32,] -0.0099278759
## [33,] 0.0197859578
## [34,] -0.0022681797
## [35,] 0.0203360392
## [36,] -0.0152161040
## [37,] -0.0049268188
## [38,] 0.0197133219
## [39,] 0.0208419520
## [40,] -0.0079565331
## [41,] -0.0194345596
## [42,] 0.0160550093
## [43,] -0.0107721804
## [44,] 0.0098734495
## [45,] -0.0156719744
## [46,] -0.0125660687
## [47,] -0.0052329723
## [48,] 0.0271504689
## [49,] -0.0138073548
## [50,] -0.0085590069
## [51,] -0.0097478653
## [52,] 0.0003463403
## [53,] 0.0126435300
## [54,] -0.0155290746
## [55,] -0.0160873510
## [56,] 0.0148809245
## [57,] -0.0234726983
## [58,] -0.0028437686
## [59,] -0.0054560766
## [60,] 0.0003662338
## [61,] -0.0019385015
## [62,] -0.0213126312
## [63,] -0.0164646701
## [64,] -0.0175098641
## [65,] -0.0037894514
## [66,] -0.0126925534
## [67,] 0.0134153160
## [68,] -0.0097143569
## [69,] 0.0016162875
## [70,] 0.0288425293
## [71,] 0.0199816720
## [72,] 0.0065775045
## [73,] -0.0079136664
## [74,] 0.0115551990
## [75,] 0.0068629583
## [76,] -0.0128121950
## [77,] 0.0100829313
## [78,] -0.0203604491
## [79,] -0.0192588759
## [80,] -0.0023722256
## [81,] -0.0115563773
## [82,] -0.0117758604
## [83,] 0.0023973549
## [84,] -0.0154711038
## [85,] -0.0157841361
## [86,] 0.0128805691
## [87,] -0.0046601789
## [88,] -0.0055509745
## [89,] -0.0128760887
## [90,] 0.0065673093
## [91,] 0.0089941544
## [92,] -0.0062238876
## [93,] -0.0182543821
## [94,] 0.0142195350
## [95,] 0.0135074119
## [96,] 0.0066943169
## [97,] 0.0044519258
## [98,] 0.0274719371
## [99,] -0.0244344798
## [100,] 0.0023465561
## [101,] 0.0005884054
## [102,] -0.0214409268
## [103,] -0.0109776503
## [104,] 0.0056939497
## [105,] -0.0052014908
## [106,] -0.0026188085
## [107,] -0.0217147822
## [108,] -0.0005424435
## [109,] 0.0200321753
## [110,] 0.0269124539
## [111,] -0.0198908073
## [112,] 0.0095217615
## [113,] -0.0120873633
## [114,] -0.0021066386
## [115,] 0.0050308206
## [116,] 0.0041626477
## [117,] -0.0253965791
## [118,] 0.0207869138
## [119,] 0.0043440107
## [120,] -0.0158761052
## [121,] 0.0156699333
## [122,] -0.0191884914
## [123,] -0.0149727723
## [124,] -0.0066446113
## [125,] 0.0090990246
## [126,] 0.0187605444
## [127,] -0.0082980805
## [128,] -0.0412513312
## [129,] -0.0035875216
## [130,] 0.0249161738
## [131,] -0.0074224216
## [132,] -0.0124158490
## [133,] 0.0129144954
## [134,] 0.0098229200
## [135,] 0.0074880750
## [136,] 0.0065066187
## [137,] 0.0019303201
## [138,] 0.0111105378
## [139,] 0.0150239973
## [140,] -0.0027287745
## [141,] -0.0015196991
## [142,] 0.0060173034
## [143,] -0.0050990406
## [144,] 0.0224212861
## [145,] -0.0071241875
## [146,] 0.0038148270
## [147,] -0.0049106321
## [148,] -0.0038652699
## [149,] -0.0184485449
## [150,] -0.0059056406
## [151,] -0.0171204309
## [152,] 0.0050161981
## [153,] 0.0038451590
## [154,] -0.0002077944
## [155,] -0.0103418353
## [156,] -0.0078265083
## [157,] -0.0061523772
## [158,] 0.0190827594
## [159,] -0.0111740273
## [160,] 0.0104141686
## [161,] 0.0117585585
## [162,] 0.0143510551
## [163,] 0.0014843359
## [164,] -0.0186941909
## [165,] 0.0124850801
## [166,] -0.0259382915
## [167,] -0.0146935716
## [168,] 0.0207746433
## [169,] 0.0030980461
## [170,] 0.0136724840
## [171,] -0.0100481735
## [172,] 0.0146432473
## [173,] 0.0228407297
## [174,] 0.0033491625
## [175,] -0.0156913955
## [176,] 0.0012305765
## [177,] -0.0057096863
## [178,] -0.0071656259
## [179,] 0.0195350176
## [180,] 0.0099704222
## [181,] 0.0012273109
## [182,] 0.0070060646
## [183,] -0.0278156482
## [184,] 0.0197966714
## [185,] 0.0107824365
## [186,] -0.0040862075
## [187,] 0.0048302563
## [188,] 0.0411239319
## [189,] -0.0276598662
## [190,] 0.0156765747
## [191,] -0.0077621291
## [192,] 0.0192193465
## [193,] 0.0095794285
## [194,] 0.0230249072
## [195,] 0.0098530344
## [196,] 0.0084168218
## [197,] -0.0008843606
## [198,] 0.0039782276
## [199,] 0.0218622926
## [200,] 0.0053506295
## [201,] -0.0205744681
## [202,] -0.0217580011
plot(Laptop_pca$x,xlim=xlim,ylim=xlim)
#The above graph is a scatter plot which shows us the first principal component score (x-axis) against the second principal component score (y-axis), with the limits of both axes set to the range of the first principal component scores.We calculate the diagonal elements of the covariance matrix of the principal component scores (Laptop_pca$x), sets the x-axis limits (xlim) to the range of the first column of the scores, and then attempts to create a plot of the principal component scores.
Laptop$Brand <- as.factor(Laptop$Brand)
out <- sapply(1:5, function(i){plot(Laptop$Brand,Laptop_pca$x[,i],xlab=paste("PC",i,sep=""),ylab="Brand")})
#The above graph shows us five seperate boxplots one for each of the first five principal components (PC1 to PC5). Each plot will show the scores of the corresponding principal component (Laptop_pca$x[,i]) on the y-axis, and the laptop brands (Laptop$Brand) on the x-axis.It also shows us the the distribution of laptop brands along the principal component axes. How each laptop brand is positioned relative to the others in the space defined by the principal components. Any patterns or clusters that might exist among the laptop brands based on their feature values (represented by the principal component scores).
library(factoextra)
## Welcome! Want to learn more? See two factoextra-related books at https://goo.gl/ve3WBa
library(FactoMineR)
library(ggfortify)
library(psych)
##
## Attaching package: 'psych'
##
## The following objects are masked from 'package:ggplot2':
##
## %+%, alpha
library(corrplot)
## corrplot 0.92 loaded
library(devtools)
## Loading required package: usethis
fviz_eig(Laptop_pca, addlabels = TRUE)
# The above graph gives us a a scree plot, which is a line plot showing the magnitude of each eigenvalue. This plot helps I decide how many principal components to retain based on the "elbow" point, where the eigenvalues start to level off.It also tells us about the proportion of variance of each component.
library(cluster)
library(readr)
library(factoextra)
library(magrittr)
library(NbClust)
Laptop <- read.csv("/Users/tusharkishan/Desktop/Multivariate/Assignment\ 1/Laptop_price.csv")
Laptop
## Brand Processor_Speed RAM_Size Storage_Capacity Screen_Size Weight
## 1 Asus 3.830296 16 512 11.18515 2.641094
## 2 Acer 2.912833 4 1000 11.31137 3.260012
## 3 Lenovo 3.241627 4 256 11.85302 2.029061
## 4 Acer 3.806248 16 512 12.28036 4.573865
## 5 Acer 3.268097 32 1000 14.99088 4.193472
## 6 HP 1.881348 16 256 11.94396 4.840268
## 7 Lenovo 2.940721 32 256 11.71325 4.344846
## 8 Lenovo 3.016788 4 256 15.58831 2.941120
## 9 Lenovo 2.560327 4 512 15.02633 2.743620
## 10 Acer 3.341111 32 512 13.61195 4.093149
## 11 Asus 3.835918 4 1000 14.29586 3.092338
## 12 Lenovo 3.813921 32 512 12.87190 3.698645
## 13 Acer 2.627098 8 512 13.89500 2.018772
## 14 HP 1.783095 16 256 14.04004 2.185657
## 15 Asus 3.962103 8 256 13.32342 3.606104
## 16 HP 3.597245 32 256 16.43943 3.698215
## 17 Asus 1.811657 16 256 11.09637 4.254359
## 18 Acer 3.802105 32 256 15.69303 2.395896
## 19 Dell 3.674741 16 256 11.74630 3.539549
## 20 Asus 2.797095 16 256 15.78528 2.583343
## 21 HP 2.978189 16 1000 14.69547 2.279588
## 22 Acer 2.497507 16 1000 16.05967 3.231487
## 23 Asus 1.636904 32 1000 11.58509 2.490010
## 24 Dell 2.337993 16 1000 14.35388 2.665346
## 25 Dell 3.507134 16 256 14.00653 2.952664
## 26 Lenovo 1.511580 8 1000 15.23716 2.778165
## 27 Lenovo 2.333748 4 256 14.20574 2.262774
## 28 HP 2.495422 4 1000 14.24441 2.269749
## 29 Asus 2.843489 8 512 13.57758 2.579748
## 30 Asus 3.799639 8 1000 12.85301 2.151678
## 31 Lenovo 2.365865 32 1000 13.89359 3.879371
## 32 Asus 2.367383 32 256 11.71095 2.861980
## 33 Asus 3.343753 32 1000 16.76908 2.839238
## 34 Dell 2.630545 8 512 15.28646 2.995995
## 35 Lenovo 2.061512 8 256 16.71480 3.988389
## 36 Acer 2.631099 16 256 12.36036 4.611902
## 37 Lenovo 1.852143 32 1000 16.27605 4.277261
## 38 Acer 1.940967 32 256 15.85274 4.182588
## 39 Dell 2.745919 32 256 15.06291 3.453174
## 40 HP 2.547314 4 256 14.75018 4.081417
## 41 Asus 3.787115 16 256 12.89930 3.658287
## 42 Dell 2.405985 32 256 15.89846 2.648752
## 43 Asus 2.951471 32 256 14.00909 2.625765
## 44 HP 3.080661 32 512 11.42535 2.889176
## 45 HP 1.532736 4 1000 12.87718 4.732408
## 46 Dell 3.158843 4 512 16.61178 3.642245
## 47 HP 1.945090 8 256 16.10408 4.201716
## 48 Acer 3.902676 16 256 16.89143 3.039676
## 49 HP 1.871657 8 1000 14.76796 3.223147
## 50 Asus 2.536560 16 512 12.48506 2.376697
## 51 Asus 1.713374 4 1000 11.97689 2.513885
## 52 Asus 3.992186 32 512 12.12149 4.482070
## 53 Asus 2.755488 8 256 11.11877 3.754516
## 54 Acer 2.988463 32 1000 13.34409 3.012597
## 55 Lenovo 1.667691 8 1000 12.14857 4.408554
## 56 Dell 3.374901 4 256 13.46993 2.739560
## 57 Asus 2.024764 4 1000 16.60997 4.928098
## 58 HP 3.745136 4 512 13.58324 3.034453
## 59 Asus 2.012849 8 512 16.26791 3.011933
## 60 HP 1.976719 16 512 14.63303 2.935736
## 61 HP 1.591374 8 512 12.48279 2.366335
## 62 Asus 2.680167 16 256 13.13513 2.333411
## 63 Acer 2.912103 8 1000 11.50352 3.944315
## 64 HP 1.664272 8 512 13.00078 4.625354
## 65 HP 3.438819 4 256 15.06525 4.371562
## 66 Asus 2.633222 32 1000 11.43267 2.423323
## 67 HP 2.810976 32 1000 12.23241 3.636746
## 68 HP 2.601907 16 256 13.28865 2.316775
## 69 Asus 2.501908 32 256 16.89230 2.135884
## 70 Asus 2.899101 8 512 15.70917 3.969158
## 71 Dell 1.888101 8 1000 15.40092 3.605457
## 72 Acer 1.954820 4 1000 11.69715 2.246071
## 73 Acer 3.654464 4 256 15.68598 2.104818
## 74 HP 3.865289 32 1000 15.71161 4.969269
## 75 Acer 2.433273 16 512 14.60662 2.090064
## 76 HP 2.176862 32 1000 16.94217 3.333585
## 77 Dell 3.109999 32 256 12.95152 3.513857
## 78 Asus 2.521835 32 256 16.64763 2.351840
## 79 Asus 1.563466 32 512 16.48839 2.507185
## 80 Asus 1.890381 8 512 11.06888 3.055415
## 81 Acer 3.289931 16 1000 13.70070 4.285028
## 82 Dell 3.147310 8 1000 16.86263 3.521247
## 83 Acer 1.567740 16 256 11.61873 3.913706
## 84 Acer 2.054930 4 512 14.28671 4.955524
## 85 Dell 2.077687 32 512 16.87375 4.304016
## 86 Dell 3.179732 8 512 14.33297 3.303084
## 87 Dell 1.549276 16 1000 12.13889 3.339326
## 88 Dell 1.760271 4 512 14.49310 3.856316
## 89 Asus 3.499790 4 256 12.22664 3.996096
## 90 Lenovo 1.946362 32 256 14.11823 3.502133
## 91 Lenovo 3.131865 16 1000 11.44425 3.934584
## 92 Dell 2.095457 8 1000 14.63290 2.070597
## 93 Lenovo 1.748603 32 512 14.10074 3.288869
## 94 Lenovo 2.107930 8 1000 15.44097 2.836814
## 95 Dell 3.305667 4 256 14.78420 2.387523
## 96 Lenovo 3.639241 8 512 14.29764 2.298640
## 97 Acer 3.575550 8 256 15.13867 3.809576
## 98 HP 2.492959 32 512 11.86365 3.570802
## 99 HP 3.170213 8 1000 14.57216 2.760752
## 100 Dell 2.012461 32 512 12.03266 3.412850
## 101 Asus 2.232869 4 512 16.55313 3.476697
## 102 Dell 3.740840 32 256 11.41000 2.585027
## 103 Asus 1.532505 32 256 13.58225 3.956279
## 104 HP 1.713771 16 512 15.17478 4.342758
## 105 Dell 2.019716 8 1000 13.74813 4.374391
## 106 Acer 1.566331 4 1000 11.55257 3.807409
## 107 Lenovo 1.953589 32 256 14.32027 3.534916
## 108 Asus 2.957604 4 1000 14.84979 2.183021
## 109 Lenovo 2.553561 16 256 15.22275 2.863494
## 110 Lenovo 3.731679 8 1000 13.23956 2.279814
## 111 Dell 3.543609 32 512 14.38196 4.891469
## 112 Lenovo 2.354543 8 256 13.70412 2.405240
## 113 Acer 2.148559 16 256 15.03234 2.455326
## 114 Lenovo 2.449231 16 512 14.50134 4.668730
## 115 Dell 2.975737 4 256 14.15454 4.831785
## 116 Acer 2.170159 32 1000 12.49715 4.297487
## 117 HP 3.060372 4 1000 11.01211 2.016215
## 118 Lenovo 2.523529 16 256 12.04449 2.004039
## 119 Dell 2.880118 8 1000 11.70240 3.134302
## 120 HP 2.590316 4 256 13.69451 2.430186
## 121 HP 2.236164 4 512 14.67355 2.055158
## 122 Asus 3.871133 8 256 12.27851 3.392200
## 123 Acer 3.409014 4 512 16.63434 4.829186
## 124 Lenovo 1.850283 8 1000 11.04009 2.971459
## 125 Dell 3.671170 32 512 15.63381 3.983422
## 126 Asus 2.718578 8 1000 14.75123 3.956706
## 127 Acer 3.736381 32 256 13.24133 2.753240
## 128 Asus 3.499638 8 1000 11.30293 3.951276
## 129 Acer 2.563034 16 256 14.76492 2.637002
## 130 Acer 1.556173 16 256 13.31368 2.366022
## 131 Lenovo 2.171693 32 512 16.61760 4.104150
## 132 Acer 2.854086 32 512 14.25194 2.340322
## 133 Asus 3.083696 16 512 16.63791 4.990728
## 134 Acer 2.144719 32 512 12.32290 2.550357
## 135 Lenovo 1.848390 8 1000 15.35436 3.782426
## 136 Lenovo 3.587326 8 1000 14.70349 3.234124
## 137 Asus 3.961005 16 1000 15.43645 2.379159
## 138 HP 2.814225 4 256 12.28801 2.083532
## 139 HP 1.929198 8 1000 14.98997 3.868197
## 140 Acer 2.180768 32 1000 13.98824 4.420273
## 141 Dell 1.545977 4 1000 15.45695 4.526047
## 142 Acer 3.785747 4 512 12.96227 3.448140
## 143 Asus 1.794378 8 1000 16.34034 4.332366
## 144 Asus 2.941291 8 256 11.50581 4.018541
## 145 Asus 2.185138 4 512 15.84314 4.172764
## 146 Asus 2.885445 4 256 16.16792 3.477797
## 147 Asus 3.128551 16 1000 15.90351 3.900235
## 148 Lenovo 3.574355 32 512 14.07636 4.416578
## 149 HP 2.016053 16 256 13.63031 3.193653
## 150 Asus 1.527490 8 1000 16.97757 4.417937
## 151 Dell 1.842214 16 256 12.37503 3.776051
## 152 Dell 3.750047 16 256 14.28126 2.497703
## 153 Dell 3.684725 16 256 15.02405 2.074052
## 154 Dell 2.993533 16 1000 15.20521 3.088261
## 155 Lenovo 3.001292 32 1000 12.22415 3.640089
## 156 Dell 3.162592 32 256 14.92396 4.519461
## 157 Asus 1.938428 4 512 15.91022 2.382457
## 158 Acer 3.786030 8 512 11.30011 4.400619
## 159 Dell 2.546926 16 1000 16.46913 4.589027
## 160 Lenovo 2.457846 4 1000 11.17702 2.452062
## 161 Lenovo 2.797294 4 1000 13.13583 4.554783
## 162 Dell 1.617415 4 1000 11.09488 4.974361
## 163 Acer 1.915708 32 1000 11.46287 4.180516
## 164 Dell 3.345084 16 512 16.46701 4.354309
## 165 Lenovo 1.706997 16 1000 13.12916 4.983246
## 166 HP 3.007880 8 256 13.54863 3.816444
## 167 Asus 2.113373 16 256 12.29207 2.923659
## 168 Lenovo 2.473239 16 512 14.58257 4.512593
## 169 Dell 2.221734 4 256 14.56882 3.843457
## 170 Asus 2.389182 8 512 13.23320 3.743586
## 171 Dell 3.297615 16 512 12.99821 2.760907
## 172 Dell 2.242804 32 256 16.30979 4.269003
## 173 HP 2.916012 16 1000 13.29971 2.245002
## 174 Asus 2.690126 4 256 13.96101 4.772861
## 175 Asus 3.159178 32 256 12.69983 2.977470
## 176 HP 3.842074 4 512 15.72062 2.383324
## 177 Lenovo 3.331430 16 256 13.38469 3.327100
## 178 Dell 2.037351 32 512 14.08167 2.127410
## 179 Acer 1.577958 8 1000 12.52014 4.053879
## 180 Dell 2.155660 8 1000 16.92596 4.708117
## 181 Dell 2.987695 32 1000 12.74897 4.511789
## 182 Lenovo 1.628565 32 256 15.62446 2.382108
## 183 Dell 2.740916 4 512 13.56497 2.378813
## 184 HP 2.992107 32 1000 12.23730 4.440303
## 185 HP 2.335610 4 512 15.79831 4.772763
## 186 Asus 3.427281 16 512 13.00164 3.382009
## 187 Acer 1.766496 4 1000 16.19116 3.496913
## 188 Dell 1.687844 32 1000 16.49154 2.954786
## 189 Dell 3.320472 32 512 16.15894 4.682795
## 190 Lenovo 2.738728 16 1000 11.21005 3.934709
## 191 HP 3.221006 32 512 15.72424 2.864755
## 192 Acer 2.587068 32 512 13.46804 2.896349
## 193 Asus 2.116005 8 1000 16.24234 4.673600
## 194 HP 3.547756 8 256 14.82773 2.040902
## 195 Asus 3.498540 16 1000 16.00186 2.968180
## 196 Lenovo 3.236741 4 256 13.99659 3.663070
## 197 Lenovo 2.180363 8 512 14.21015 2.444652
## 198 Dell 2.975577 4 512 11.86633 2.276296
## 199 Acer 2.402435 32 256 15.70392 4.445829
## 200 Asus 1.728955 8 512 13.51634 4.683213
## 201 HP 3.793284 16 256 14.00048 4.470819
## 202 Lenovo 1.842047 16 256 15.71059 4.696364
## Price
## 1 17395.093
## 2 31607.606
## 3 9291.024
## 4 17436.728
## 5 32917.991
## 6 9543.720
## 7 10390.137
## 8 9214.485
## 9 16372.175
## 10 18501.833
## 11 31967.608
## 12 18534.109
## 13 17495.984
## 14 9731.982
## 15 9831.390
## 16 11038.928
## 17 8971.513
## 18 10915.057
## 19 9637.892
## 20 9593.111
## 21 31965.357
## 22 32025.837
## 23 32764.274
## 24 32114.821
## 25 9929.514
## 26 31623.814
## 27 9264.934
## 28 31549.800
## 29 16729.551
## 30 31747.605
## 31 32817.517
## 32 10605.766
## 33 32810.024
## 34 17059.609
## 35 8973.590
## 36 9912.492
## 37 32801.646
## 38 10174.195
## 39 10325.365
## 40 9221.138
## 41 10233.786
## 42 10333.322
## 43 10781.539
## 44 18167.300
## 45 31381.406
## 46 17124.220
## 47 9280.142
## 48 9701.089
## 49 31673.696
## 50 17493.650
## 51 31339.160
## 52 18495.181
## 53 9140.170
## 54 33151.041
## 55 31612.052
## 56 9081.899
## 57 31650.730
## 58 17076.681
## 59 16983.636
## 60 17283.376
## 61 16788.669
## 62 10029.582
## 63 31879.663
## 64 17008.986
## 65 9362.266
## 66 33008.899
## 67 32703.613
## 68 9859.675
## 69 10566.171
## 70 16702.351
## 71 31232.364
## 72 31169.851
## 73 9486.595
## 74 33005.181
## 75 17299.663
## 76 32993.532
## 77 10514.889
## 78 10859.963
## 79 18310.414
## 80 16833.276
## 81 32339.842
## 82 31954.950
## 83 9437.652
## 84 16879.492
## 85 18371.753
## 86 16959.088
## 87 31849.950
## 88 16691.854
## 89 9454.454
## 90 10327.844
## 91 31996.360
## 92 31624.843
## 93 18295.119
## 94 31362.162
## 95 9107.981
## 96 17146.714
## 97 9491.272
## 98 17807.040
## 99 32097.517
## 100 18042.956
## 101 16746.849
## 102 11055.045
## 103 10462.142
## 104 17155.738
## 105 31568.083
## 106 31197.896
## 107 10711.444
## 108 31533.202
## 109 9478.121
## 110 31512.884
## 111 18702.479
## 112 9143.216
## 113 9819.848
## 114 17407.538
## 115 9126.589
## 116 32689.030
## 117 31828.830
## 118 9415.943
## 119 31601.437
## 120 9328.965
## 121 16523.523
## 122 9829.331
## 123 17204.648
## 124 31515.503
## 125 18366.445
## 126 31416.860
## 127 10905.979
## 128 32336.203
## 129 9790.714
## 130 9168.639
## 131 18277.153
## 132 18464.505
## 133 17376.020
## 134 17980.796
## 135 31389.465
## 136 31772.921
## 137 32342.706
## 138 8995.590
## 139 31299.789
## 140 32806.591
## 141 31236.541
## 142 16954.665
## 143 31558.997
## 144 9054.154
## 145 16824.803
## 146 9162.532
## 147 32252.676
## 148 18492.162
## 149 9850.111
## 150 31521.461
## 151 9771.527
## 152 9926.275
## 153 9941.850
## 154 32153.742
## 155 33063.165
## 156 10791.995
## 157 16769.080
## 158 16953.655
## 159 32215.489
## 160 31218.308
## 161 31293.448
## 162 30967.940
## 163 32653.960
## 164 17857.159
## 165 31661.078
## 166 9750.099
## 167 9801.241
## 168 17108.253
## 169 9000.734
## 170 16757.014
## 171 17684.869
## 172 10314.434
## 173 31802.523
## 174 9084.372
## 175 10869.936
## 176 17080.491
## 177 9960.398
## 178 18215.276
## 179 31123.001
## 180 31442.695
## 181 32908.693
## 182 10282.910
## 183 17196.585
## 184 32653.100
## 185 16613.509
## 186 17629.778
## 187 31216.575
## 188 32159.485
## 189 18787.382
## 190 31817.738
## 191 18502.217
## 192 17967.133
## 193 31428.705
## 194 9241.110
## 195 32141.825
## 196 9141.793
## 197 16929.316
## 198 16795.165
## 199 10241.803
## 200 16724.506
## 201 10263.360
## 202 9881.336
matstd.Laptop <- scale(Laptop[,2:7])
# K-means, k=2, 3, 4, 5, 6
# Centers (k's) are numbers thus, 10 random sets are chosen
(kmeans2.Laptop <- kmeans(matstd.Laptop,2,nstart = 10))
## K-means clustering with 2 clusters of sizes 132, 70
##
## Cluster means:
## Processor_Speed RAM_Size Storage_Capacity Screen_Size Weight
## 1 0.1270101 0.06318927 -0.6866947 0.03676012 -0.07201374
## 2 -0.2395048 -0.11915691 1.2949101 -0.06931909 0.13579735
## Price
## 1 -0.6849653
## 2 1.2916489
##
## Clustering vector:
## [1] 1 2 1 1 2 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 2 2 2 2 1 2 1 2 1 2 2 1 2 1 1 1 2
## [38] 1 1 1 1 1 1 1 2 1 1 1 2 1 2 1 1 2 2 1 2 1 1 1 1 1 2 1 1 2 2 1 1 1 2 2 1 2
## [75] 1 2 1 1 1 1 2 2 1 1 1 1 2 1 1 1 2 2 1 2 1 1 1 1 2 1 1 1 1 1 2 2 1 2 1 2 1
## [112] 1 1 1 1 2 2 1 2 1 1 1 1 2 1 2 1 2 1 1 1 1 1 1 2 2 2 1 2 2 2 1 2 1 1 1 2 1
## [149] 1 2 1 1 1 2 2 1 1 1 2 2 2 2 2 1 2 1 1 1 1 1 1 1 2 1 1 1 1 1 2 2 2 1 1 2 1
## [186] 1 2 2 1 2 1 1 2 1 2 1 1 1 1 1 1 1
##
## Within cluster sum of squares by cluster:
## [1] 550.9053 286.6025
## (between_SS / total_SS = 30.6 %)
##
## Available components:
##
## [1] "cluster" "centers" "totss" "withinss" "tot.withinss"
## [6] "betweenss" "size" "iter" "ifault"
# Computing the percentage of variation accounted for. Two clusters
perc.var.2 <- round(100*(1 - kmeans2.Laptop$betweenss/kmeans2.Laptop$totss),1)
names(perc.var.2) <- "Perc. 2 clus"
perc.var.2
## Perc. 2 clus
## 69.4
#Ans) The cluster-sum of squares is observed to be 69.4%.
# Computing the percentage of variation accounted for. Three clusters
(kmeans3.Laptop <- kmeans(matstd.Laptop,3,nstart = 10))
## K-means clustering with 3 clusters of sizes 40, 92, 70
##
## Cluster means:
## Processor_Speed RAM_Size Storage_Capacity Screen_Size Weight
## 1 0.1013840 1.4664278 -0.6701622 0.16449541 -0.009714417
## 2 0.1381519 -0.5469144 -0.6938828 -0.01877696 -0.099100408
## 3 -0.2395048 -0.1191569 1.2949101 -0.06931909 0.135797346
## Price
## 1 -0.5814308
## 2 -0.7299803
## 3 1.2916489
##
## Clustering vector:
## [1] 2 3 2 2 3 2 1 2 2 1 3 1 2 2 2 1 2 1 2 2 3 3 3 3 2 3 2 3 2 3 3 1 3 2 2 2 3
## [38] 1 1 2 2 1 1 1 3 2 2 2 3 2 3 1 2 3 3 2 3 2 2 2 2 2 3 2 2 3 3 2 1 2 3 3 2 3
## [75] 2 3 1 1 1 2 3 3 2 2 1 2 3 2 2 1 3 3 1 3 2 2 2 1 3 1 2 1 1 2 3 3 1 3 2 3 1
## [112] 2 2 2 2 3 3 2 3 2 2 2 2 3 1 3 1 3 2 2 1 1 2 1 3 3 3 2 3 3 3 2 3 2 2 2 3 1
## [149] 2 3 2 2 2 3 3 1 2 2 3 3 3 3 3 2 3 2 2 2 2 2 2 1 3 2 1 2 2 1 3 3 3 1 2 3 2
## [186] 2 3 3 1 3 1 1 3 2 3 2 2 2 1 2 2 2
##
## Within cluster sum of squares by cluster:
## [1] 125.7788 310.2908 286.6025
## (between_SS / total_SS = 40.1 %)
##
## Available components:
##
## [1] "cluster" "centers" "totss" "withinss" "tot.withinss"
## [6] "betweenss" "size" "iter" "ifault"
perc.var.3 <- round(100*(1 - kmeans3.Laptop$betweenss/kmeans3.Laptop$totss),1)
names(perc.var.3) <- "Perc. 3 clus"
perc.var.3
## Perc. 3 clus
## 59.9
#Ans) The cluster-sum of squares is observed to be 59.9%
# Computing the percentage of variation accounted for. Four clusters
(kmeans4.Laptop <- kmeans(matstd.Laptop,4,nstart = 10))
## K-means clustering with 4 clusters of sizes 40, 70, 33, 59
##
## Cluster means:
## Processor_Speed RAM_Size Storage_Capacity Screen_Size Weight
## 1 0.1013840 1.4664278 -0.6701622 0.16449541 -0.009714417
## 2 -0.2395048 -0.1191569 1.2949101 -0.06931909 0.135797346
## 3 -0.3059291 -0.5736439 -0.6132169 0.33344115 0.982862179
## 4 0.3865362 -0.5319640 -0.7390010 -0.21578031 -0.704265923
## Price
## 1 -0.5814308
## 2 1.2916489
## 3 -0.6561676
## 4 -0.7712654
##
## Clustering vector:
## [1] 4 2 4 3 2 3 1 4 4 1 2 1 4 4 4 1 3 1 4 4 2 2 2 2 4 2 4 2 4 2 2 1 2 4 3 3 2
## [38] 1 1 3 4 1 1 1 2 3 3 4 2 4 2 1 4 2 2 4 2 4 3 4 4 4 2 3 3 2 2 4 1 3 2 2 4 2
## [75] 4 2 1 1 1 4 2 2 3 3 1 4 2 3 4 1 2 2 1 2 4 4 4 1 2 1 3 1 1 3 2 2 1 2 4 2 1
## [112] 4 4 3 3 2 2 4 2 4 4 4 3 2 1 2 1 2 4 4 1 1 3 1 2 2 2 4 2 2 2 4 2 4 3 3 2 1
## [149] 4 2 3 4 4 2 2 1 4 4 2 2 2 2 2 3 2 4 4 3 3 3 4 1 2 3 1 4 4 1 2 2 2 1 4 2 3
## [186] 4 2 2 1 2 1 1 2 4 2 4 4 4 1 3 3 3
##
## Within cluster sum of squares by cluster:
## [1] 125.77876 286.60247 84.94374 147.92504
## (between_SS / total_SS = 46.5 %)
##
## Available components:
##
## [1] "cluster" "centers" "totss" "withinss" "tot.withinss"
## [6] "betweenss" "size" "iter" "ifault"
perc.var.4 <- round(100*(1 - kmeans4.Laptop$betweenss/kmeans4.Laptop$totss),1)
names(perc.var.4) <- "Perc. 4 clus"
perc.var.4
## Perc. 4 clus
## 53.5
#Ans) The cluster-sum of squares is observed to be 53.5%
# Computing the percentage of variation accounted for. Five clusters
(kmeans5.Laptop <- kmeans(matstd.Laptop,5,nstart = 10))
## K-means clustering with 5 clusters of sizes 35, 33, 40, 59, 35
##
## Cluster means:
## Processor_Speed RAM_Size Storage_Capacity Screen_Size Weight
## 1 -0.2062761 -0.2387255863 1.2949101 0.9141723 0.078401726
## 2 -0.3059291 -0.5736439174 -0.6132169 0.3334411 0.982862179
## 3 0.1013840 1.4664277608 -0.6701622 0.1644954 -0.009714417
## 4 0.3865362 -0.5319640288 -0.7390010 -0.2157803 -0.704265923
## 5 -0.2727335 0.0004117733 1.2949101 -1.0528105 0.193192966
## Price
## 1 1.2869054
## 2 -0.6561676
## 3 -0.5814308
## 4 -0.7712654
## 5 1.2963924
##
## Clustering vector:
## [1] 4 5 4 2 1 2 3 4 4 3 1 3 4 4 4 3 2 3 4 4 1 1 5 1 4 1 4 1 4 5 5 3 1 4 2 2 1
## [38] 3 3 2 4 3 3 3 5 2 2 4 1 4 5 3 4 5 5 4 1 4 2 4 4 4 5 2 2 5 5 4 3 2 1 5 4 1
## [75] 4 1 3 3 3 4 5 1 2 2 3 4 5 2 4 3 5 1 3 1 4 4 4 3 1 3 2 3 3 2 5 5 3 1 4 5 3
## [112] 4 4 2 2 5 5 4 5 4 4 4 2 5 3 1 3 5 4 4 3 3 2 3 1 1 1 4 1 5 1 4 1 4 2 2 1 3
## [149] 4 1 2 4 4 1 5 3 4 4 1 5 5 5 5 2 5 4 4 2 2 2 4 3 5 2 3 4 4 3 5 1 5 3 4 5 2
## [186] 4 1 1 3 5 3 3 1 4 1 4 4 4 3 2 2 2
##
## Within cluster sum of squares by cluster:
## [1] 101.99438 84.94374 125.77876 147.92504 115.58999
## (between_SS / total_SS = 52.2 %)
##
## Available components:
##
## [1] "cluster" "centers" "totss" "withinss" "tot.withinss"
## [6] "betweenss" "size" "iter" "ifault"
perc.var.5 <- round(100*(1 - kmeans5.Laptop$betweenss/kmeans5.Laptop$totss),1)
names(perc.var.5) <- "Perc. 5 clus"
perc.var.5
## Perc. 5 clus
## 47.8
(kmeans6.Laptop <- kmeans(matstd.Laptop,6,nstart = 10))
## K-means clustering with 6 clusters of sizes 32, 38, 28, 32, 39, 33
##
## Cluster means:
## Processor_Speed RAM_Size Storage_Capacity Screen_Size Weight
## 1 -0.49703147 -0.44407180 -0.6752138 -0.1707471 -0.94956874
## 2 -0.10015623 -0.25733124 1.2949101 0.7999372 -0.03413889
## 3 -0.34458415 -0.65201733 -0.5922233 0.4695615 1.05022041
## 4 -0.40498121 0.04492511 1.2949101 -1.1015610 0.33759663
## 5 0.06554427 1.46642776 -0.6603181 0.2081842 0.01413451
## 6 1.20492342 -0.49645202 -0.8091578 -0.3318383 -0.27506158
## Price
## 1 -0.7124623
## 2 1.2851397
## 3 -0.6413132
## 4 1.2993786
## 5 -0.5726982
## 6 -0.8280191
##
## Clustering vector:
## [1] 6 4 6 6 2 3 5 6 1 5 2 5 1 1 6 5 3 5 6 1 2 2 4 2 6 2 1 2 1 2 4 5 2 1 3 3 2
## [38] 5 5 3 6 5 5 5 4 3 3 6 2 1 4 5 6 4 4 6 2 6 1 1 1 1 4 3 3 4 4 1 5 3 2 4 6 2
## [75] 1 2 5 5 5 1 4 2 1 3 5 6 4 3 6 5 4 2 5 2 6 6 6 5 2 5 3 6 5 3 4 4 5 2 1 2 5
## [112] 1 1 3 3 4 4 1 4 1 1 6 3 4 5 2 5 4 1 1 5 5 3 5 2 2 2 1 2 4 2 6 2 6 3 3 2 5
## [149] 1 2 1 6 6 2 4 5 1 6 2 4 4 4 4 3 4 6 1 3 3 3 6 5 2 3 5 6 6 5 4 2 4 5 1 4 3
## [186] 6 2 2 5 4 5 5 2 6 2 6 1 1 5 3 6 3
##
## Within cluster sum of squares by cluster:
## [1] 54.66611 119.89233 60.88046 98.29516 119.63995 73.02399
## (between_SS / total_SS = 56.4 %)
##
## Available components:
##
## [1] "cluster" "centers" "totss" "withinss" "tot.withinss"
## [6] "betweenss" "size" "iter" "ifault"
#Ans) The cluster-sum of squares is observed to be 48%
# Computing the percentage of variation accounted for. Six clusters
perc.var.6 <- round(100*(1 - kmeans6.Laptop$betweenss/kmeans6.Laptop$totss),1)
names(perc.var.6) <- "Perc. 6 clus"
perc.var.6
## Perc. 6 clus
## 43.6
#Ans) The cluster-sum of squares is observed to be 43.8%
attributes(perc.var.6)
## $names
## [1] "Perc. 6 clus"
Variance_List <- c(perc.var.2,perc.var.3,perc.var.4,perc.var.5,perc.var.6)
Variance_List
## Perc. 2 clus Perc. 3 clus Perc. 4 clus Perc. 5 clus Perc. 6 clus
## 69.4 59.9 53.5 47.8 43.6
plot(Variance_List)
#Ans) From the graph we can observe that having 4 clusters is optimal, because the graph seems to get flatter after that point
clus1 <- Laptop[kmeans4.Laptop$cluster == 1,]
colnames(clus1) <- "Cluster 1"
clus2 <- Laptop[kmeans4.Laptop$cluster == 2, ]
colnames(clus2) <- "Cluster 2"
clus3 <- Laptop[kmeans4.Laptop$cluster == 3, ]
colnames(clus3) <- "Cluster 3"
clus4 <- Laptop[kmeans4.Laptop$cluster == 4, ]
colnames(clus4) <- "Cluster 4"
#AnsThe above code creates subsets of the Laptop dataset based on the clusters assigned by the kmeans4.Laptop clustering algorithm. Here's a breakdown of each part:
#clus1 <- Laptop[kmeans4.Laptop$cluster == 1,]: This line creates a subset of Laptop where the cluster assignment in kmeans4.Laptop is equal to 1. This subset is stored in clus1.
#colnames(clus1) <- "Cluster 1": This line renames the column of clus1 to "Cluster 1". This is useful for identifying which cluster the data in clus1 belongs to.
#Similarly, the next lines create subsets clus2, clus3, and clus4 for clusters 2, 3, and 4 respectively, and rename their columns accordingly.
list(clus1,clus2,clus3,clus4)
## [[1]]
## Cluster 1 NA NA NA NA NA NA
## 7 Lenovo 2.940721 32 256 11.71325 4.344846 10390.14
## 10 Acer 3.341111 32 512 13.61195 4.093149 18501.83
## 12 Lenovo 3.813921 32 512 12.87190 3.698645 18534.11
## 16 HP 3.597245 32 256 16.43943 3.698215 11038.93
## 18 Acer 3.802105 32 256 15.69303 2.395896 10915.06
## 32 Asus 2.367383 32 256 11.71095 2.861980 10605.77
## 38 Acer 1.940967 32 256 15.85274 4.182588 10174.20
## 39 Dell 2.745919 32 256 15.06291 3.453174 10325.36
## 42 Dell 2.405985 32 256 15.89846 2.648752 10333.32
## 43 Asus 2.951471 32 256 14.00909 2.625765 10781.54
## 44 HP 3.080661 32 512 11.42535 2.889176 18167.30
## 52 Asus 3.992186 32 512 12.12149 4.482070 18495.18
## 69 Asus 2.501908 32 256 16.89230 2.135884 10566.17
## 77 Dell 3.109999 32 256 12.95152 3.513857 10514.89
## 78 Asus 2.521835 32 256 16.64763 2.351840 10859.96
## 79 Asus 1.563466 32 512 16.48839 2.507185 18310.41
## 85 Dell 2.077687 32 512 16.87375 4.304016 18371.75
## 90 Lenovo 1.946362 32 256 14.11823 3.502133 10327.84
## 93 Lenovo 1.748603 32 512 14.10074 3.288869 18295.12
## 98 HP 2.492959 32 512 11.86365 3.570802 17807.04
## 100 Dell 2.012461 32 512 12.03266 3.412850 18042.96
## 102 Dell 3.740840 32 256 11.41000 2.585027 11055.05
## 103 Asus 1.532505 32 256 13.58225 3.956279 10462.14
## 107 Lenovo 1.953589 32 256 14.32027 3.534916 10711.44
## 111 Dell 3.543609 32 512 14.38196 4.891469 18702.48
## 125 Dell 3.671170 32 512 15.63381 3.983422 18366.44
## 127 Acer 3.736381 32 256 13.24133 2.753240 10905.98
## 131 Lenovo 2.171693 32 512 16.61760 4.104150 18277.15
## 132 Acer 2.854086 32 512 14.25194 2.340322 18464.51
## 134 Acer 2.144719 32 512 12.32290 2.550357 17980.80
## 148 Lenovo 3.574355 32 512 14.07636 4.416578 18492.16
## 156 Dell 3.162592 32 256 14.92396 4.519461 10791.99
## 172 Dell 2.242804 32 256 16.30979 4.269003 10314.43
## 175 Asus 3.159178 32 256 12.69983 2.977470 10869.94
## 178 Dell 2.037351 32 512 14.08167 2.127410 18215.28
## 182 Lenovo 1.628565 32 256 15.62446 2.382108 10282.91
## 189 Dell 3.320472 32 512 16.15894 4.682795 18787.38
## 191 HP 3.221006 32 512 15.72424 2.864755 18502.22
## 192 Acer 2.587068 32 512 13.46804 2.896349 17967.13
## 199 Acer 2.402435 32 256 15.70392 4.445829 10241.80
##
## [[2]]
## Cluster 2 NA NA NA NA NA NA
## 2 Acer 2.912833 4 1000 11.31137 3.260012 31607.61
## 5 Acer 3.268097 32 1000 14.99088 4.193472 32917.99
## 11 Asus 3.835918 4 1000 14.29586 3.092338 31967.61
## 21 HP 2.978189 16 1000 14.69547 2.279588 31965.36
## 22 Acer 2.497507 16 1000 16.05967 3.231487 32025.84
## 23 Asus 1.636904 32 1000 11.58509 2.490010 32764.27
## 24 Dell 2.337993 16 1000 14.35388 2.665346 32114.82
## 26 Lenovo 1.511580 8 1000 15.23716 2.778165 31623.81
## 28 HP 2.495422 4 1000 14.24441 2.269749 31549.80
## 30 Asus 3.799639 8 1000 12.85301 2.151678 31747.60
## 31 Lenovo 2.365865 32 1000 13.89359 3.879371 32817.52
## 33 Asus 3.343753 32 1000 16.76908 2.839238 32810.02
## 37 Lenovo 1.852143 32 1000 16.27605 4.277261 32801.65
## 45 HP 1.532736 4 1000 12.87718 4.732408 31381.41
## 49 HP 1.871657 8 1000 14.76796 3.223147 31673.70
## 51 Asus 1.713374 4 1000 11.97689 2.513885 31339.16
## 54 Acer 2.988463 32 1000 13.34409 3.012597 33151.04
## 55 Lenovo 1.667691 8 1000 12.14857 4.408554 31612.05
## 57 Asus 2.024764 4 1000 16.60997 4.928098 31650.73
## 63 Acer 2.912103 8 1000 11.50352 3.944315 31879.66
## 66 Asus 2.633222 32 1000 11.43267 2.423323 33008.90
## 67 HP 2.810976 32 1000 12.23241 3.636746 32703.61
## 71 Dell 1.888101 8 1000 15.40092 3.605457 31232.36
## 72 Acer 1.954820 4 1000 11.69715 2.246071 31169.85
## 74 HP 3.865289 32 1000 15.71161 4.969269 33005.18
## 76 HP 2.176862 32 1000 16.94217 3.333585 32993.53
## 81 Acer 3.289931 16 1000 13.70070 4.285028 32339.84
## 82 Dell 3.147310 8 1000 16.86263 3.521247 31954.95
## 87 Dell 1.549276 16 1000 12.13889 3.339326 31849.95
## 91 Lenovo 3.131865 16 1000 11.44425 3.934584 31996.36
## 92 Dell 2.095457 8 1000 14.63290 2.070597 31624.84
## 94 Lenovo 2.107930 8 1000 15.44097 2.836814 31362.16
## 99 HP 3.170213 8 1000 14.57216 2.760752 32097.52
## 105 Dell 2.019716 8 1000 13.74813 4.374391 31568.08
## 106 Acer 1.566331 4 1000 11.55257 3.807409 31197.90
## 108 Asus 2.957604 4 1000 14.84979 2.183021 31533.20
## 110 Lenovo 3.731679 8 1000 13.23956 2.279814 31512.88
## 116 Acer 2.170159 32 1000 12.49715 4.297487 32689.03
## 117 HP 3.060372 4 1000 11.01211 2.016215 31828.83
## 119 Dell 2.880118 8 1000 11.70240 3.134302 31601.44
## 124 Lenovo 1.850283 8 1000 11.04009 2.971459 31515.50
## 126 Asus 2.718578 8 1000 14.75123 3.956706 31416.86
## 128 Asus 3.499638 8 1000 11.30293 3.951276 32336.20
## 135 Lenovo 1.848390 8 1000 15.35436 3.782426 31389.47
## 136 Lenovo 3.587326 8 1000 14.70349 3.234124 31772.92
## 137 Asus 3.961005 16 1000 15.43645 2.379159 32342.71
## 139 HP 1.929198 8 1000 14.98997 3.868197 31299.79
## 140 Acer 2.180768 32 1000 13.98824 4.420273 32806.59
## 141 Dell 1.545977 4 1000 15.45695 4.526047 31236.54
## 143 Asus 1.794378 8 1000 16.34034 4.332366 31559.00
## 147 Asus 3.128551 16 1000 15.90351 3.900235 32252.68
## 150 Asus 1.527490 8 1000 16.97757 4.417937 31521.46
## 154 Dell 2.993533 16 1000 15.20521 3.088261 32153.74
## 155 Lenovo 3.001292 32 1000 12.22415 3.640089 33063.17
## 159 Dell 2.546926 16 1000 16.46913 4.589027 32215.49
## 160 Lenovo 2.457846 4 1000 11.17702 2.452062 31218.31
## 161 Lenovo 2.797294 4 1000 13.13583 4.554783 31293.45
## 162 Dell 1.617415 4 1000 11.09488 4.974361 30967.94
## 163 Acer 1.915708 32 1000 11.46287 4.180516 32653.96
## 165 Lenovo 1.706997 16 1000 13.12916 4.983246 31661.08
## 173 HP 2.916012 16 1000 13.29971 2.245002 31802.52
## 179 Acer 1.577958 8 1000 12.52014 4.053879 31123.00
## 180 Dell 2.155660 8 1000 16.92596 4.708117 31442.70
## 181 Dell 2.987695 32 1000 12.74897 4.511789 32908.69
## 184 HP 2.992107 32 1000 12.23730 4.440303 32653.10
## 187 Acer 1.766496 4 1000 16.19116 3.496913 31216.57
## 188 Dell 1.687844 32 1000 16.49154 2.954786 32159.49
## 190 Lenovo 2.738728 16 1000 11.21005 3.934709 31817.74
## 193 Asus 2.116005 8 1000 16.24234 4.673600 31428.70
## 195 Asus 3.498540 16 1000 16.00186 2.968180 32141.82
##
## [[3]]
## Cluster 3 NA NA NA NA NA NA
## 4 Acer 3.806248 16 512 12.28036 4.573865 17436.728
## 6 HP 1.881348 16 256 11.94396 4.840268 9543.720
## 17 Asus 1.811657 16 256 11.09637 4.254359 8971.513
## 35 Lenovo 2.061512 8 256 16.71480 3.988389 8973.590
## 36 Acer 2.631099 16 256 12.36036 4.611902 9912.492
## 40 HP 2.547314 4 256 14.75018 4.081417 9221.138
## 46 Dell 3.158843 4 512 16.61178 3.642245 17124.220
## 47 HP 1.945090 8 256 16.10408 4.201716 9280.142
## 59 Asus 2.012849 8 512 16.26791 3.011933 16983.636
## 64 HP 1.664272 8 512 13.00078 4.625354 17008.986
## 65 HP 3.438819 4 256 15.06525 4.371562 9362.266
## 70 Asus 2.899101 8 512 15.70917 3.969158 16702.351
## 83 Acer 1.567740 16 256 11.61873 3.913706 9437.652
## 84 Acer 2.054930 4 512 14.28671 4.955524 16879.492
## 88 Dell 1.760271 4 512 14.49310 3.856316 16691.854
## 101 Asus 2.232869 4 512 16.55313 3.476697 16746.849
## 104 HP 1.713771 16 512 15.17478 4.342758 17155.738
## 114 Lenovo 2.449231 16 512 14.50134 4.668730 17407.538
## 115 Dell 2.975737 4 256 14.15454 4.831785 9126.589
## 123 Acer 3.409014 4 512 16.63434 4.829186 17204.648
## 133 Asus 3.083696 16 512 16.63791 4.990728 17376.020
## 145 Asus 2.185138 4 512 15.84314 4.172764 16824.803
## 146 Asus 2.885445 4 256 16.16792 3.477797 9162.532
## 151 Dell 1.842214 16 256 12.37503 3.776051 9771.527
## 164 Dell 3.345084 16 512 16.46701 4.354309 17857.159
## 168 Lenovo 2.473239 16 512 14.58257 4.512593 17108.253
## 169 Dell 2.221734 4 256 14.56882 3.843457 9000.734
## 170 Asus 2.389182 8 512 13.23320 3.743586 16757.014
## 174 Asus 2.690126 4 256 13.96101 4.772861 9084.372
## 185 HP 2.335610 4 512 15.79831 4.772763 16613.509
## 200 Asus 1.728955 8 512 13.51634 4.683213 16724.506
## 201 HP 3.793284 16 256 14.00048 4.470819 10263.360
## 202 Lenovo 1.842047 16 256 15.71059 4.696364 9881.336
##
## [[4]]
## Cluster 4 NA NA NA NA NA NA
## 1 Asus 3.830296 16 512 11.18515 2.641094 17395.093
## 3 Lenovo 3.241627 4 256 11.85302 2.029061 9291.024
## 8 Lenovo 3.016788 4 256 15.58831 2.941120 9214.485
## 9 Lenovo 2.560327 4 512 15.02633 2.743620 16372.175
## 13 Acer 2.627098 8 512 13.89500 2.018772 17495.984
## 14 HP 1.783095 16 256 14.04004 2.185657 9731.982
## 15 Asus 3.962103 8 256 13.32342 3.606104 9831.390
## 19 Dell 3.674741 16 256 11.74630 3.539549 9637.892
## 20 Asus 2.797095 16 256 15.78528 2.583343 9593.111
## 25 Dell 3.507134 16 256 14.00653 2.952664 9929.514
## 27 Lenovo 2.333748 4 256 14.20574 2.262774 9264.934
## 29 Asus 2.843489 8 512 13.57758 2.579748 16729.551
## 34 Dell 2.630545 8 512 15.28646 2.995995 17059.609
## 41 Asus 3.787115 16 256 12.89930 3.658287 10233.786
## 48 Acer 3.902676 16 256 16.89143 3.039676 9701.089
## 50 Asus 2.536560 16 512 12.48506 2.376697 17493.650
## 53 Asus 2.755488 8 256 11.11877 3.754516 9140.170
## 56 Dell 3.374901 4 256 13.46993 2.739560 9081.899
## 58 HP 3.745136 4 512 13.58324 3.034453 17076.681
## 60 HP 1.976719 16 512 14.63303 2.935736 17283.376
## 61 HP 1.591374 8 512 12.48279 2.366335 16788.669
## 62 Asus 2.680167 16 256 13.13513 2.333411 10029.582
## 68 HP 2.601907 16 256 13.28865 2.316775 9859.675
## 73 Acer 3.654464 4 256 15.68598 2.104818 9486.595
## 75 Acer 2.433273 16 512 14.60662 2.090064 17299.663
## 80 Asus 1.890381 8 512 11.06888 3.055415 16833.276
## 86 Dell 3.179732 8 512 14.33297 3.303084 16959.088
## 89 Asus 3.499790 4 256 12.22664 3.996096 9454.454
## 95 Dell 3.305667 4 256 14.78420 2.387523 9107.981
## 96 Lenovo 3.639241 8 512 14.29764 2.298640 17146.714
## 97 Acer 3.575550 8 256 15.13867 3.809576 9491.272
## 109 Lenovo 2.553561 16 256 15.22275 2.863494 9478.121
## 112 Lenovo 2.354543 8 256 13.70412 2.405240 9143.216
## 113 Acer 2.148559 16 256 15.03234 2.455326 9819.848
## 118 Lenovo 2.523529 16 256 12.04449 2.004039 9415.943
## 120 HP 2.590316 4 256 13.69451 2.430186 9328.965
## 121 HP 2.236164 4 512 14.67355 2.055158 16523.523
## 122 Asus 3.871133 8 256 12.27851 3.392200 9829.331
## 129 Acer 2.563034 16 256 14.76492 2.637002 9790.714
## 130 Acer 1.556173 16 256 13.31368 2.366022 9168.639
## 138 HP 2.814225 4 256 12.28801 2.083532 8995.590
## 142 Acer 3.785747 4 512 12.96227 3.448140 16954.665
## 144 Asus 2.941291 8 256 11.50581 4.018541 9054.154
## 149 HP 2.016053 16 256 13.63031 3.193653 9850.111
## 152 Dell 3.750047 16 256 14.28126 2.497703 9926.275
## 153 Dell 3.684725 16 256 15.02405 2.074052 9941.850
## 157 Asus 1.938428 4 512 15.91022 2.382457 16769.080
## 158 Acer 3.786030 8 512 11.30011 4.400619 16953.655
## 166 HP 3.007880 8 256 13.54863 3.816444 9750.099
## 167 Asus 2.113373 16 256 12.29207 2.923659 9801.241
## 171 Dell 3.297615 16 512 12.99821 2.760907 17684.869
## 176 HP 3.842074 4 512 15.72062 2.383324 17080.491
## 177 Lenovo 3.331430 16 256 13.38469 3.327100 9960.398
## 183 Dell 2.740916 4 512 13.56497 2.378813 17196.585
## 186 Asus 3.427281 16 512 13.00164 3.382009 17629.778
## 194 HP 3.547756 8 256 14.82773 2.040902 9241.110
## 196 Lenovo 3.236741 4 256 13.99659 3.663070 9141.793
## 197 Lenovo 2.180363 8 512 14.21015 2.444652 16929.316
## 198 Dell 2.975577 4 512 11.86633 2.276296 16795.165
new_data <- Laptop[, c("Processor_Speed", "RAM_Size", "Storage_Capacity", "Screen_Size", "Weight", "Price")] %>% na.omit() %>% scale()
fviz_nbclust(new_data, kmeans, method = "gap_stat")
#Ans) From the graph it is clear that 2 would be the optimal number of clusters
set.seed(123)
km.res <- kmeans(new_data, 3, nstart = 25)
fviz_cluster(km.res, data = new_data,
ellipse.type = "convex",
palette = "jco",
ggtheme = theme_minimal())
#Ans) 3 clusters are formed. Cluster 3 is isolated whereas cluster 1 and 2 are band together closely. Also the size of cluster 3 is smaller compared to cluster 1 and 2
Laptop_pca <- prcomp(Laptop[, c("Processor_Speed", "RAM_Size", "Storage_Capacity", "Screen_Size", "Weight", "Price")])
Laptop_pca
## Standard deviations (1, .., p=6):
## [1] 9441.4739851 23.1635587 3.9965115 1.7069020 0.8679056
## [6] 0.5519118
##
## Rotation (n x k) = (6 x 6):
## PC1 PC2 PC3 PC4
## Processor_Speed 1.200092e-05 0.007031165 0.10123775 0.0477822371
## RAM_Size 3.560757e-05 0.448832873 -0.88874572 -0.0217818525
## Storage_Capacity -3.347465e-02 -0.893078228 -0.44525792 -0.0147261539
## Screen_Size 5.428539e-06 0.003649304 0.03214410 -0.9963526363
## Weight -1.133516e-05 0.001368107 -0.01930287 -0.0656257166
## Price -9.994396e-01 0.029928325 0.01488316 0.0004883595
## PC5 PC6
## Processor_Speed -0.0519294081 -0.992331434
## RAM_Size -0.0242910144 -0.087267378
## Storage_Capacity -0.0113540266 -0.051868488
## Screen_Size -0.0673947091 -0.041143849
## Weight 0.9960131463 -0.057241638
## Price 0.0003671339 0.001722654
summary(Laptop_pca)
## Importance of components:
## PC1 PC2 PC3 PC4 PC5 PC6
## Standard deviation 9441 23.16356 3.997 1.707 0.8679 0.5519
## Proportion of Variance 1 0.00001 0.000 0.000 0.0000 0.0000
## Cumulative Proportion 1 1.00000 1.000 1.000 1.0000 1.0000
PC1 <- Laptop_pca$x[,1]
PC2 <- Laptop_pca$x[,2]
Laptop_pca_df <- as.data.frame(Laptop_pca$x)
matstd.new_pca <- Laptop_pca_df
res.nbclust <- matstd.new_pca %>% scale() %>% NbClust(distance = "euclidean", min.nc = 2, max.nc = 10, method = "complete", index ="all")
## *** : The Hubert index is a graphical method of determining the number of clusters.
## In the plot of Hubert index, we seek a significant knee that corresponds to a
## significant increase of the value of the measure i.e the significant peak in Hubert
## index second differences plot.
##
## *** : The D index is a graphical method of determining the number of clusters.
## In the plot of D index, we seek a significant knee (the significant peak in Dindex
## second differences plot) that corresponds to a significant increase of the value of
## the measure.
##
## *******************************************************************
## * Among all indices:
## * 7 proposed 2 as the best number of clusters
## * 4 proposed 3 as the best number of clusters
## * 7 proposed 9 as the best number of clusters
## * 5 proposed 10 as the best number of clusters
##
## ***** Conclusion *****
##
## * According to the majority rule, the best number of clusters is 2
##
##
## *******************************************************************
fviz_nbclust(matstd.new_pca, kmeans, method = "silhouette")
#Ans) Optimal number of clusters would be 3
set.seed(123)
kmeans3.Laptop_pca <- kmeans(matstd.new_pca, 3, nstart = 25)
kmeans3.Laptop_pca
## K-means clustering with 3 clusters of sizes 70, 72, 60
##
## Cluster means:
## PC1 PC2 PC3 PC4 PC5 PC6
## 1 -12195.133 -2.1017426 -0.07748098 0.04302343 -0.01391717 0.005168993
## 2 9938.904 1.3302929 -0.06604261 0.08020315 -0.02569941 0.009751980
## 3 2300.971 0.8556816 0.16964560 -0.14643778 0.04707599 -0.017732867
##
## Clustering vector:
## [1] 3 1 2 3 1 2 2 2 3 3 1 3 3 2 2 2 2 2 2 2 1 1 1 1 2 1 2 1 3 1 1 2 1 3 2 2 1
## [38] 2 2 2 2 2 2 3 1 3 2 2 1 3 1 3 2 1 1 2 1 3 3 3 3 2 1 3 2 1 1 2 2 3 1 1 2 1
## [75] 3 1 2 2 3 3 1 1 2 3 3 3 1 3 2 2 1 1 3 1 2 3 2 3 1 3 3 2 2 3 1 1 2 1 2 1 3
## [112] 2 2 3 2 1 1 2 1 2 3 2 3 1 3 1 2 1 2 2 3 3 3 3 1 1 1 2 1 1 1 3 1 2 3 2 1 3
## [149] 2 1 2 2 2 1 1 2 3 3 1 1 1 1 1 3 1 2 2 3 2 3 3 2 1 2 2 3 2 3 1 1 1 2 3 1 3
## [186] 3 1 1 3 1 3 3 1 2 1 2 3 3 2 3 2 2
##
## Within cluster sum of squares by cluster:
## [1] 24477103 25708766 26904983
## (between_SS / total_SS = 99.6 %)
##
## Available components:
##
## [1] "cluster" "centers" "totss" "withinss" "tot.withinss"
## [6] "betweenss" "size" "iter" "ifault"
km.Laptop_pca <- kmeans(matstd.new_pca, 3, nstart =25)
fviz_cluster(km.Laptop_pca, data = matstd.new_pca,
ellipse.type = "convex",
palette = "jco",
ggtheme = theme_minimal())
#Ans) 3 clusters are formed. But compared to the previous cluster we notice that all the 3 clusters are banded closely together. No cluster is isloated from each other as shown in the previous observation and the size of all the 3 clusters are almost equal.
# Factor Analysis
library(psych)
Laptop <- read.csv("/Users/tusharkishan/Desktop/Multivariate/Assignment\ 1/Laptop_price.csv")
attach(Laptop)
## The following objects are masked from Laptop (pos = 13):
##
## Brand, Price, Processor_Speed, RAM_Size, Screen_Size,
## Storage_Capacity, Weight
## The following objects are masked from Laptop (pos = 14):
##
## Brand, Price, Processor_Speed, RAM_Size, Screen_Size,
## Storage_Capacity, Weight
## The following objects are masked from Laptop (pos = 17):
##
## Brand, Price, Processor_Speed, RAM_Size, Screen_Size,
## Storage_Capacity, Weight
Laptop[1]
## Brand
## 1 Asus
## 2 Acer
## 3 Lenovo
## 4 Acer
## 5 Acer
## 6 HP
## 7 Lenovo
## 8 Lenovo
## 9 Lenovo
## 10 Acer
## 11 Asus
## 12 Lenovo
## 13 Acer
## 14 HP
## 15 Asus
## 16 HP
## 17 Asus
## 18 Acer
## 19 Dell
## 20 Asus
## 21 HP
## 22 Acer
## 23 Asus
## 24 Dell
## 25 Dell
## 26 Lenovo
## 27 Lenovo
## 28 HP
## 29 Asus
## 30 Asus
## 31 Lenovo
## 32 Asus
## 33 Asus
## 34 Dell
## 35 Lenovo
## 36 Acer
## 37 Lenovo
## 38 Acer
## 39 Dell
## 40 HP
## 41 Asus
## 42 Dell
## 43 Asus
## 44 HP
## 45 HP
## 46 Dell
## 47 HP
## 48 Acer
## 49 HP
## 50 Asus
## 51 Asus
## 52 Asus
## 53 Asus
## 54 Acer
## 55 Lenovo
## 56 Dell
## 57 Asus
## 58 HP
## 59 Asus
## 60 HP
## 61 HP
## 62 Asus
## 63 Acer
## 64 HP
## 65 HP
## 66 Asus
## 67 HP
## 68 HP
## 69 Asus
## 70 Asus
## 71 Dell
## 72 Acer
## 73 Acer
## 74 HP
## 75 Acer
## 76 HP
## 77 Dell
## 78 Asus
## 79 Asus
## 80 Asus
## 81 Acer
## 82 Dell
## 83 Acer
## 84 Acer
## 85 Dell
## 86 Dell
## 87 Dell
## 88 Dell
## 89 Asus
## 90 Lenovo
## 91 Lenovo
## 92 Dell
## 93 Lenovo
## 94 Lenovo
## 95 Dell
## 96 Lenovo
## 97 Acer
## 98 HP
## 99 HP
## 100 Dell
## 101 Asus
## 102 Dell
## 103 Asus
## 104 HP
## 105 Dell
## 106 Acer
## 107 Lenovo
## 108 Asus
## 109 Lenovo
## 110 Lenovo
## 111 Dell
## 112 Lenovo
## 113 Acer
## 114 Lenovo
## 115 Dell
## 116 Acer
## 117 HP
## 118 Lenovo
## 119 Dell
## 120 HP
## 121 HP
## 122 Asus
## 123 Acer
## 124 Lenovo
## 125 Dell
## 126 Asus
## 127 Acer
## 128 Asus
## 129 Acer
## 130 Acer
## 131 Lenovo
## 132 Acer
## 133 Asus
## 134 Acer
## 135 Lenovo
## 136 Lenovo
## 137 Asus
## 138 HP
## 139 HP
## 140 Acer
## 141 Dell
## 142 Acer
## 143 Asus
## 144 Asus
## 145 Asus
## 146 Asus
## 147 Asus
## 148 Lenovo
## 149 HP
## 150 Asus
## 151 Dell
## 152 Dell
## 153 Dell
## 154 Dell
## 155 Lenovo
## 156 Dell
## 157 Asus
## 158 Acer
## 159 Dell
## 160 Lenovo
## 161 Lenovo
## 162 Dell
## 163 Acer
## 164 Dell
## 165 Lenovo
## 166 HP
## 167 Asus
## 168 Lenovo
## 169 Dell
## 170 Asus
## 171 Dell
## 172 Dell
## 173 HP
## 174 Asus
## 175 Asus
## 176 HP
## 177 Lenovo
## 178 Dell
## 179 Acer
## 180 Dell
## 181 Dell
## 182 Lenovo
## 183 Dell
## 184 HP
## 185 HP
## 186 Asus
## 187 Acer
## 188 Dell
## 189 Dell
## 190 Lenovo
## 191 HP
## 192 Acer
## 193 Asus
## 194 HP
## 195 Asus
## 196 Lenovo
## 197 Lenovo
## 198 Dell
## 199 Acer
## 200 Asus
## 201 HP
## 202 Lenovo
fit.pc <- principal(Laptop[-1], nfactors=3, rotate="varimax")
fit.pc
## Principal Components Analysis
## Call: principal(r = Laptop[-1], nfactors = 3, rotate = "varimax")
## Standardized loadings (pattern matrix) based upon correlation matrix
## RC1 RC2 RC3 h2 u2 com
## Processor_Speed -0.20 -0.54 0.34 0.45 0.552 2.0
## RAM_Size -0.03 0.05 0.92 0.85 0.154 1.0
## Storage_Capacity 0.99 0.04 -0.06 0.98 0.017 1.0
## Screen_Size -0.16 0.68 -0.01 0.49 0.515 1.1
## Weight 0.16 0.63 0.27 0.49 0.513 1.5
## Price 0.99 0.04 0.00 0.98 0.019 1.0
##
## RC1 RC2 RC3
## SS loadings 2.05 1.15 1.03
## Proportion Var 0.34 0.19 0.17
## Cumulative Var 0.34 0.53 0.71
## Proportion Explained 0.48 0.27 0.24
## Cumulative Proportion 0.48 0.76 1.00
##
## Mean item complexity = 1.3
## Test of the hypothesis that 3 components are sufficient.
##
## The root mean square of the residuals (RMSR) is 0.15
## with the empirical chi square 143.39 with prob < NA
##
## Fit based upon off diagonal values = 0.68
fa.diagram(fit.pc)
#Ans) The parallel analysis tell us that we should have 5 factors. However, 3-factors have been extracted after performing factor analysis. The three factors (RC1, RC2, RC3) explain 48%, 27%, and 24% of the total variance, respectively. Together, they cumulatively explain 100% of the variance in the data.The factor loadings indicate the strength and direction of the relationship between each variable and the factors. Variables with higher absolute loadings on a factor are more strongly associated with that factor. The variables in my dataset are:
#RC1: Processor_Speed, Storage_Capacity, Screen_Size, Weight, Price
#RC2: RAM_Size, Screen_Size, Weight
#RC3: RAM_Size, Storage_Capacity, Weight
#The root mean square of the residuals (RMSR) is 0.15, indicating a reasonable fit of the model to the data. The fit based on off-diagonal values is 0.68, which is acceptable.
fit.pc <- principal(Laptop[-1], nfactors=4, rotate="varimax")
fit.pc
## Principal Components Analysis
## Call: principal(r = Laptop[-1], nfactors = 4, rotate = "varimax")
## Standardized loadings (pattern matrix) based upon correlation matrix
## RC1 RC2 RC3 RC4 h2 u2 com
## Processor_Speed -0.08 0.83 0.22 0.08 0.75 0.24754 1.2
## RAM_Size -0.05 0.03 0.92 -0.03 0.86 0.14250 1.0
## Storage_Capacity 0.99 -0.09 -0.05 -0.02 1.00 0.00029 1.0
## Screen_Size -0.02 -0.04 -0.01 0.98 0.97 0.03097 1.0
## Weight 0.09 -0.63 0.36 0.19 0.57 0.43196 1.8
## Price 1.00 -0.08 0.01 -0.01 1.00 0.00094 1.0
##
## RC1 RC2 RC3 RC4
## SS loadings 2.00 1.10 1.03 1.01
## Proportion Var 0.33 0.18 0.17 0.17
## Cumulative Var 0.33 0.52 0.69 0.86
## Proportion Explained 0.39 0.21 0.20 0.20
## Cumulative Proportion 0.39 0.60 0.80 1.00
##
## Mean item complexity = 1.2
## Test of the hypothesis that 4 components are sufficient.
##
## The root mean square of the residuals (RMSR) is 0.12
## with the empirical chi square 92.95 with prob < NA
##
## Fit based upon off diagonal values = 0.79
fa.diagram(fit.pc)
#Ans) From the diagram it is clear that Price and Storage_Capacity go into one group, Screen_size, Weight and Processor_Speed go into the next group and Ram_Size goes seperately into another group. The root mean square of the residuals (RMSR) is 0.12, indicating a good fit of the model to the data. The fit based on off-diagonal values is 0.79, which is also considered good.
fit.pc <- principal(Laptop[-1], nfactors=5, rotate="varimax")
fit.pc
## Principal Components Analysis
## Call: principal(r = Laptop[-1], nfactors = 5, rotate = "varimax")
## Standardized loadings (pattern matrix) based upon correlation matrix
## RC1 RC3 RC4 RC5 RC2 h2 u2 com
## Processor_Speed -0.10 0.02 -0.02 -0.05 0.99 1 2.9e-08 1
## RAM_Size -0.04 1.00 0.01 0.03 0.02 1 3.9e-07 1
## Storage_Capacity 0.99 -0.06 -0.02 0.05 -0.08 1 1.1e-04 1
## Screen_Size -0.02 0.01 1.00 0.04 -0.02 1 8.9e-10 1
## Weight 0.07 0.03 0.04 0.99 -0.05 1 2.8e-11 1
## Price 1.00 0.00 -0.01 0.05 -0.06 1 1.1e-04 1
##
## RC1 RC3 RC4 RC5 RC2
## SS loadings 2.00 1.00 1.00 1.00 1.00
## Proportion Var 0.33 0.17 0.17 0.17 0.17
## Cumulative Var 0.33 0.50 0.67 0.83 1.00
## Proportion Explained 0.33 0.17 0.17 0.17 0.17
## Cumulative Proportion 0.33 0.50 0.67 0.83 1.00
##
## Mean item complexity = 1
## Test of the hypothesis that 5 components are sufficient.
##
## The root mean square of the residuals (RMSR) is 0
## with the empirical chi square 0 with prob < NA
##
## Fit based upon off diagonal values = 1
fa.diagram(fit.pc)
#Ans) From the diagram it is clear that only Price and Storage_Capacity go into one group. Ram_sizes goes into one group. Screen_size goes into one group. Weight goes seperately into another group and Processor_Speed also goes seperately into another group.The root mean square of the residuals (RMSR) is 0.12, indicating a good fit of the model to the data. The fit based on off-diagonal values is 0.79, which is also considered good.
for (i in c(1,3,5)) { print(fit.pc$loadings[[1,i]])}
## [1] -0.09719765
## [1] -0.02166232
## [1] 0.9935007
fit.pc$communality
## Processor_Speed RAM_Size Storage_Capacity Screen_Size
## 1.0000000 0.9999996 0.9998905 1.0000000
## Weight Price
## 1.0000000 0.9998919
#Ans)All variables have very high communalities (close to 1), indicating that the factors explain almost all of the variance in each variable.
fa.parallel(Laptop[-1])
## Warning in fa.stats(r = r, f = f, phi = phi, n.obs = n.obs, np.obs = np.obs, :
## The estimated weights for the factor scores are probably incorrect. Try a
## different factor score estimation method.
## Warning in fac(r = r, nfactors = nfactors, n.obs = n.obs, rotate = rotate, : An
## ultra-Heywood case was detected. Examine the results carefully
## Parallel analysis suggests that the number of factors = 1 and the number of components = 1
#Ans) This function will generate a plot showing the eigenvalues from my actual data and the average eigenvalues from the random data. We can use this plot to determine the number of factors to retain. From the plot it is clear that, it is better to retain one or more factors.
fa.plot(fit.pc)
#Ans) A bi-plot is created Each variable will be represented by a vector indicating its loading on each principal component, and each observation will be represented by a point. From the plot we can also see that there is no correlation between the factors
vss(Laptop[-1])
## Warning in fa.stats(r = r, f = f, phi = phi, n.obs = n.obs, np.obs = np.obs, :
## The estimated weights for the factor scores are probably incorrect. Try a
## different factor score estimation method.
## Warning in fa.stats(r = r, f = f, phi = phi, n.obs = n.obs, np.obs = np.obs, :
## An ultra-Heywood case was detected. Examine the results carefully
## Warning in fa.stats(r = r, f = f, phi = phi, n.obs = n.obs, np.obs = np.obs, :
## The estimated weights for the factor scores are probably incorrect. Try a
## different factor score estimation method.
## Warning in fa.stats(r = r, f = f, phi = phi, n.obs = n.obs, np.obs = np.obs, :
## The estimated weights for the factor scores are probably incorrect. Try a
## different factor score estimation method.
## Warning in fac(r = r, nfactors = nfactors, n.obs = n.obs, rotate = rotate, : An
## ultra-Heywood case was detected. Examine the results carefully
##
## Very Simple Structure
## Call: vss(x = Laptop[-1])
## Although the VSS complexity 1 shows 5 factors, it is probably more reasonable to think about 2 factors
## VSS complexity 2 achieves a maximimum of 0.94 with 5 factors
##
## The Velicer MAP achieves a minimum of 0.2 with 1 factors
## BIC achieves a minimum of 394.33 with 2 factors
## Sample Size adjusted BIC achieves a minimum of 407.01 with 2 factors
##
## Statistics by number of factors
## vss1 vss2 map dof chisq prob sqresid fit RMSEA BIC SABIC complex
## 1 0.52 0.00 0.20 9 548 2.7e-112 3.95 0.52 0.54 500 529 1.0
## 2 0.64 0.64 0.27 4 416 1.2e-88 2.94 0.64 0.71 394 407 1.2
## 3 0.61 0.64 0.43 0 425 NA 2.90 0.65 NA NA NA 1.2
## 4 0.74 0.76 0.82 -3 315 NA 1.85 0.78 NA NA NA 1.3
## 5 0.92 0.94 1.00 -5 306 NA 0.38 0.95 NA NA NA 1.0
## 6 0.92 0.94 NA -6 305 NA 0.38 0.95 NA NA NA 1.0
## eChisq SRMR eCRMS eBIC
## 1 10.2824 0.04119 0.053 -37
## 2 7.2582 0.03461 0.067 -14
## 3 0.0167 0.00166 NA NA
## 4 0.0026 0.00066 NA NA
## 5 0.0023 0.00062 NA NA
## 6 0.0023 0.00062 NA NA
#Ans) This function will generate a plot showing the average correlation of items within factors for different numbers of factors. It can help us determine the optimal number of factors to retain based on the simplicity of the factor structure. Based on the graph it is clear that it is optimal to retain one or more factors.
library(GGally)
## Registered S3 method overwritten by 'GGally':
## method from
## +.gg ggplot2
Laptop <- read.csv("/Users/tusharkishan/Desktop/Multivariate/Assignment\ 1/Laptop_price.csv")
str(Laptop)
## 'data.frame': 202 obs. of 7 variables:
## $ Brand : chr "Asus" "Acer" "Lenovo" "Acer" ...
## $ Processor_Speed : num 3.83 2.91 3.24 3.81 3.27 ...
## $ RAM_Size : int 16 4 4 16 32 16 32 4 4 32 ...
## $ Storage_Capacity: int 512 1000 256 512 1000 256 256 256 512 512 ...
## $ Screen_Size : num 11.2 11.3 11.9 12.3 15 ...
## $ Weight : num 2.64 3.26 2.03 4.57 4.19 ...
## $ Price : num 17395 31608 9291 17437 32918 ...
#Ans)This data frame contains information about laptops, with each row representing a different laptop and each column representing a different attribute of the laptops. Here's what each variable represents:
#Brand: The brand of the laptop (e.g., Asus, Acer, Lenovo).
#Processor_Speed: The speed of the processor in GHz.
#RAM_Size: The amount of RAM in gigabytes (GB).
#Storage_Capacity: The storage capacity of the laptop's hard drive or SSD in gigabytes (GB).
#Screen_Size: The size of the laptop screen in inches.
#Weight: The weight of the laptop in kilograms
#Price: The price of the laptop in the local currency
Laptop$Brand_numeric <- ifelse(Laptop$Brand == "Acer", 0,
ifelse(Laptop$Brand == "Asus", 1,
ifelse(Laptop$Brand == "Dell", 2,
ifelse(Laptop$Brand == "HP", 3,
ifelse(Laptop$Brand == "Lenovo", 4, NA)))))
print(Laptop$Brand_numeric)
## [1] 1 0 4 0 0 3 4 4 4 0 1 4 0 3 1 3 1 0 2 1 3 0 1 2 2 4 4 3 1 1 4 1 1 2 4 0 4
## [38] 0 2 3 1 2 1 3 3 2 3 0 3 1 1 1 1 0 4 2 1 3 1 3 3 1 0 3 3 1 3 3 1 1 2 0 0 3
## [75] 0 3 2 1 1 1 0 2 0 0 2 2 2 2 1 4 4 2 4 4 2 4 0 3 3 2 1 2 1 3 2 0 4 1 4 4 2
## [112] 4 0 4 2 0 3 4 2 3 3 1 0 4 2 1 0 1 0 0 4 0 1 0 4 4 1 3 3 0 2 0 1 1 1 1 1 4
## [149] 3 1 2 2 2 2 4 2 1 0 2 4 4 2 0 2 4 3 1 4 2 1 2 2 3 1 1 3 4 2 0 2 2 4 2 3 3
## [186] 1 0 2 2 4 3 0 1 3 1 4 4 2 0 1 3 4
str(Laptop)
## 'data.frame': 202 obs. of 8 variables:
## $ Brand : chr "Asus" "Acer" "Lenovo" "Acer" ...
## $ Processor_Speed : num 3.83 2.91 3.24 3.81 3.27 ...
## $ RAM_Size : int 16 4 4 16 32 16 32 4 4 32 ...
## $ Storage_Capacity: int 512 1000 256 512 1000 256 256 256 512 512 ...
## $ Screen_Size : num 11.2 11.3 11.9 12.3 15 ...
## $ Weight : num 2.64 3.26 2.03 4.57 4.19 ...
## $ Price : num 17395 31608 9291 17437 32918 ...
## $ Brand_numeric : num 1 0 4 0 0 3 4 4 4 0 ...
#Ans) A new column is created(Brand_numeric) where the Brand values are 'num' data type
fit <- lm(Brand_numeric ~ Processor_Speed + RAM_Size + Storage_Capacity + Screen_Size + Weight + Price, data = Laptop)
summary(fit)
##
## Call:
## lm(formula = Brand_numeric ~ Processor_Speed + RAM_Size + Storage_Capacity +
## Screen_Size + Weight + Price, data = Laptop)
##
## Residuals:
## Min 1Q Median 3Q Max
## -2.30998 -1.05648 -0.00092 1.09914 2.36555
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 2.6292947 1.0347735 2.541 0.0118 *
## Processor_Speed -0.0876721 0.1761603 -0.498 0.6193
## RAM_Size 0.0142492 0.0269495 0.529 0.5976
## Storage_Capacity 0.0111845 0.0148399 0.754 0.4520
## Screen_Size 0.0194945 0.0581154 0.335 0.7376
## Weight -0.0454740 0.1128728 -0.403 0.6875
## Price -0.0003737 0.0004949 -0.755 0.4511
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 1.388 on 195 degrees of freedom
## Multiple R-squared: 0.01296, Adjusted R-squared: -0.01741
## F-statistic: 0.4269 on 6 and 195 DF, p-value: 0.8605
#Ans) The output displays a multiple regression model that predicts the Brand_numeric variable using the Processor_Speed, RAM_Size, Storage_Capacity, Screen_Size, Weight, and Price variables from my dataset. Here's an overview of the important findings:
#Residuals: These are the differences between the observed values and the predicted values from the model. They are a measure of how well the model fits the data.
#Coefficients: These are the estimated coefficients for each predictor variable in the model. They represent the estimated effect of each predictor on the response variable. The Estimate column gives the estimated coefficient values, while the Std. Error column gives the standard errors of these estimates.
#Residual standard error: This is an estimate of the standard deviation of the residuals.
#Multiple R-squared: This is a measure of how well the model explains the variability in the response variable. It ranges from 0 to 1, with higher values indicating a better fit.
#Adjusted R-squared: This is similar to the R-squared value but adjusted for the number of predictors in the model. It is often used to compare models with different numbers of predictors.
#F-statistic: This is a test statistic that tests the overall significance of the model. It compares the fit of the intercept-only model with the fit of the current model.
#p-value: This is the probability of observing the F-statistic (or more extreme) under the null hypothesis that all the coefficients are zero. A low p-value indicates that the model is statistically significant.
fit2 <- lm(Brand_numeric ~ Processor_Speed + Storage_Capacity + Screen_Size + Weight + Price, data = Laptop)
summary(fit2)
##
## Call:
## lm(formula = Brand_numeric ~ Processor_Speed + Storage_Capacity +
## Screen_Size + Weight + Price, data = Laptop)
##
## Residuals:
## Min 1Q Median 3Q Max
## -2.22597 -1.04608 -0.00434 1.08736 2.37542
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 2.5307663 1.0159837 2.491 0.0136 *
## Processor_Speed -0.1403215 0.1450500 -0.967 0.3345
## Storage_Capacity 0.0037822 0.0049125 0.770 0.4423
## Screen_Size 0.0158044 0.0575887 0.274 0.7840
## Weight -0.0428124 0.1125531 -0.380 0.7041
## Price -0.0001269 0.0001644 -0.772 0.4411
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 1.385 on 196 degrees of freedom
## Multiple R-squared: 0.01155, Adjusted R-squared: -0.01367
## F-statistic: 0.458 on 5 and 196 DF, p-value: 0.8071
#Ans) There is not much difference compared to the 1st model ('fit'). Hence we can continue with the first model itself
coefficients(fit)
## (Intercept) Processor_Speed RAM_Size Storage_Capacity
## 2.6292947456 -0.0876721083 0.0142492065 0.0111844658
## Screen_Size Weight Price
## 0.0194945446 -0.0454739533 -0.0003736698
#Ans) The coefficients(fit) function provides the estimated coefficients for each predictor variable in the multiple regression model.These coefficients represent the estimated effect of each predictor variable on the Brand_numeric variable, holding all other variables constant. For example, a one-unit increase in Processor_Speed is associated with a decrease of approximately 0.0877 in the Brand_numeric value, all else being equal. Similarly, a one-unit increase in RAM_Size is associated with an increase of approximately 0.0142 in the Brand_numeric value, all else being equal.
ggpairs(data=Laptop, title="Relationships Between Laptop Specifications for Different Brands")
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
#Ans)A matrix of scatterplots is created showing the relationship between different laptop specifications for different brands. From the graph it is clear that there is no linear relationship between the columns.
confint(fit,level=0.95)
## 2.5 % 97.5 %
## (Intercept) 0.588510231 4.6700792605
## Processor_Speed -0.435096173 0.2597519565
## RAM_Size -0.038900754 0.0673991668
## Storage_Capacity -0.018082779 0.0404517104
## Screen_Size -0.095120880 0.1341099687
## Weight -0.268082227 0.1771343205
## Price -0.001349669 0.0006023297
#Ans) The confint function provides the 95% confidence intervals for the coefficients.These intervals give a range of values within which we can be 95% confident that the true population parameter lies for each coefficient.
fitted(fit)
## 1 2 3 4 5 6 7 8
## 1.845846 1.876841 1.932340 1.765857 1.784303 2.002100 1.838960 2.011995
## 9 10 11 12 13 14 15 16
## 2.238650 1.684445 1.727196 1.634445 1.880767 2.101944 1.681203 1.660508
## 17 18 19 20 21 22 23 24
## 2.232147 1.733505 1.864976 2.080875 2.018976 2.021827 1.995821 1.995052
## 25 26 27 28 29 30 31 32
## 1.841450 2.149075 2.056922 2.037246 2.116490 1.884230 1.893840 1.876039
## 33 34 35 36 37 38 39 40
## 1.914262 2.026212 2.217095 1.817071 1.973161 2.095378 1.986091 1.982476
## 41 42 43 44 45 46 47 48
## 1.649534 2.065789 1.814693 1.844407 2.045930 1.895204 2.091146 1.944411
## 49 50 51 52 53 54 55 56
## 2.069485 1.959808 2.129214 1.583108 1.995550 1.743331 2.005433 1.998011
## 57 58 59 60 61 62 63 64
## 1.966025 1.830165 2.127164 2.103915 2.192538 1.887732 1.804870 2.011192
## 65 66 67 68 69 70 71 72
## 1.844529 1.817124 1.876028 1.961831 2.013067 2.100151 2.227910 2.178036
## 73 74 75 76 77 78 79 80
## 1.894343 1.678137 2.095743 1.928888 1.839431 1.886949 2.040017 2.090756
## 81 82 83 84 85 86 87 88
## 1.741123 1.879828 2.105023 1.978388 1.897818 1.983073 2.089346 2.128345
## 89 90 91 92 93 94 95 96
## 1.766472 2.034621 1.855278 2.117897 1.947409 2.195869 2.035964 1.917664
## 97 98 99 100 101 102 103 104
## 1.868319 2.008098 1.814479 1.972548 2.123783 1.594471 1.989621 2.121241
## 105 106 107 108 109 110 111 112
## 2.023736 2.127798 1.893095 2.018673 2.121488 1.979605 1.570425 2.141320
## 113 114 115 116 117 118 119 120
## 2.044152 1.934720 1.934511 1.912773 1.831968 2.124479 1.952350 1.992922
## 121 122 123 124 125 126 127 128
## 2.234946 1.679305 1.789683 2.069243 1.750504 2.057522 1.678614 1.578538
## 129 130 131 132 133 134 135 136
## 2.005226 2.309981 1.929020 1.833276 1.917882 2.029059 2.163732 1.880235
## 137 138 139 140 141 142 143 144
## 1.801724 2.086209 2.179153 1.891399 2.158576 1.841281 2.099332 2.006940
## 145 146 147 148 149 150 151 152
## 2.053345 2.029818 1.848284 1.661956 1.983554 2.145288 1.977204 1.847408
## 153 154 155 156 157 158 159 160
## 1.881061 1.920400 1.724675 1.723997 2.178517 1.822914 1.892876 2.096321
## 161 162 163 164 165 166 167 168
## 1.981050 2.147258 1.933342 1.740787 2.090644 1.790063 1.979472 2.053133
## 169 170 171 172 173 174 175 176
## 2.100664 2.086420 1.814164 2.021493 2.059637 1.974233 1.721934 1.891519
## 177 178 179 180 181 182 183 184
## 1.816164 2.004373 2.219416 2.105446 1.754181 2.159568 1.902861 1.842577
## 185 186 187 188 189 190 191 192
## 2.090949 1.795205 2.207816 2.291860 1.602393 1.951919 1.791870 2.001973
## 193 194 195 196 197 198 199 200
## 2.102393 2.038601 1.901570 1.956014 2.118457 2.003834 2.014785 2.119242
## 201 202
## 1.622460 1.959361
#Ans) The fitted function provides the fitted values for the multiple regression model fit.Each value in the output corresponds to a fitted value for each observation from my dataset.
residuals(fit)
## 1 2 3 4 5 6
## -0.845846488 -1.876840952 2.067660157 -1.765856861 -1.784303020 0.997900110
## 7 8 9 10 11 12
## 2.161039692 1.988004789 1.761349791 -1.684445195 -0.727196433 2.365554758
## 13 14 15 16 17 18
## -1.880766754 0.898056339 -0.681202842 1.339492318 -1.232146769 -1.733504801
## 19 20 21 22 23 24
## 0.135024259 -1.080874815 0.981023819 -2.021826782 -0.995821040 0.004947799
## 25 26 27 28 29 30
## 0.158550202 1.850925056 1.943078246 0.962753954 -1.116490204 -0.884230170
## 31 32 33 34 35 36
## 2.106160060 -0.876039067 -0.914261617 -0.026212254 1.782904937 -1.817071193
## 37 38 39 40 41 42
## 2.026839328 -2.095377925 0.013909334 1.017524357 -0.649533800 -0.065789149
## 43 44 45 46 47 48
## -0.814692691 1.155593068 0.954069770 0.104795779 0.908854017 -1.944410640
## 49 50 51 52 53 54
## 0.930515052 -0.959807613 -1.129213593 -0.583108057 -0.995549671 -1.743331028
## 55 56 57 58 59 60
## 1.994567369 0.001989239 -0.966024844 1.169834811 -1.127163860 0.896084905
## 61 62 63 64 65 66
## 0.807462349 -0.887731836 -1.804870206 0.988807908 1.155471489 -0.817124169
## 67 68 69 70 71 72
## 1.123972413 1.038168636 -1.013067012 -1.100150910 -0.227910070 -2.178036299
## 73 74 75 76 77 78
## -1.894343129 1.321862718 -2.095743228 1.071111588 0.160568651 -0.886948810
## 79 80 81 82 83 84
## -1.040017467 -1.090755921 -1.741123309 0.120171551 -2.105023020 -1.978387846
## 85 86 87 88 89 90
## 0.102182436 0.016926813 -0.089346243 -0.128344697 -0.766471881 1.965379437
## 91 92 93 94 95 96
## 2.144722286 -0.117896773 2.052590918 1.804130626 -0.035964046 2.082335762
## 97 98 99 100 101 102
## -1.868319260 0.991901593 1.185521452 0.027452266 -1.123783372 0.405529376
## 103 104 105 106 107 108
## -0.989620704 0.878758817 -0.023735971 -2.127797626 2.106904823 -1.018673360
## 109 110 111 112 113 114
## 1.878511591 2.020394911 0.429575245 1.858679622 -2.044151701 2.065280015
## 115 116 117 118 119 120
## 0.065488953 -1.912772939 1.168032483 1.875520565 0.047649686 1.007077678
## 121 122 123 124 125 126
## 0.765054235 -0.679304501 -1.789682664 1.930756935 0.249496348 -1.057521567
## 127 128 129 130 131 132
## -1.678614429 -0.578537825 -2.005225558 -2.309980917 2.070979670 -1.833276209
## 133 134 135 136 137 138
## -0.917881695 -2.029058578 1.836267781 2.119764523 -0.801723692 0.913791452
## 139 140 141 142 143 144
## 0.820847208 -1.891398709 -0.158576243 -1.841280919 -1.099332221 -1.006940444
## 145 146 147 148 149 150
## -1.053344812 -1.029817718 -0.848284036 2.338044239 1.016446140 -1.145288164
## 151 152 153 154 155 156
## 0.022795905 0.152591796 0.118939384 0.079599652 2.275324702 0.276002502
## 157 158 159 160 161 162
## -1.178516606 -1.822914425 0.107123890 1.903678996 2.018949673 -0.147258190
## 163 164 165 166 167 168
## -1.933342230 0.259213107 1.909356477 1.209937321 -0.979471817 1.946867139
## 169 170 171 172 173 174
## -0.100663973 -1.086420237 0.185836338 -0.021492570 0.940363491 -0.974233418
## 175 176 177 178 179 180
## -0.721934328 1.108480511 2.183835587 -0.004373202 -2.219415681 -0.105445639
## 181 182 183 184 185 186
## 0.245819445 1.840431852 0.097138833 1.157422796 0.909051053 -0.795204511
## 187 188 189 190 191 192
## -2.207815790 -0.291860314 0.397607313 2.048081004 1.208130405 -2.001972719
## 193 194 195 196 197 198
## -1.102392800 0.961399117 -0.901569590 2.043985840 1.881543152 -0.003834040
## 199 200 201 202
## -2.014785345 -1.119242294 1.377540163 2.040638609
#Ans) The residuals function gives I the residuals (the differences between the observed values and the fitted values) for the multiple regression model fit. These residuals indicate how well the model fits the data for each observation.
anova(fit)
## Analysis of Variance Table
##
## Response: Brand_numeric
## Df Sum Sq Mean Sq F value Pr(>F)
## Processor_Speed 1 2.83 2.82680 1.4673 0.2272
## RAM_Size 1 0.62 0.61847 0.3210 0.5716
## Storage_Capacity 1 0.02 0.02293 0.0119 0.9132
## Screen_Size 1 0.08 0.08071 0.0419 0.8380
## Weight 1 0.29 0.28670 0.1488 0.7001
## Price 1 1.10 1.09836 0.5701 0.4511
## Residuals 195 375.67 1.92649
#Ans) The ANOVA table shows the analysis of variance for the regression model fit.The table includes the following columns:
#Df: Degrees of freedom for each source of variation.
#Sum Sq: Sum of squares, which measures the total variation explained by each variable or the residuals.
#Mean Sq: Mean sum of squares, which is the sum of squares divided by its degrees of freedom.
#F value: The F-statistic, which is a ratio of the mean square for the variable to the mean square of the residuals. It indicates whether there is a significant difference in means between groups (or in this case, whether the variable is a significant predictor of Brand_numeric).
#Pr(>F): The p-value associated with the F-statistic, which indicates the probability of observing the data if the null hypothesis (that the variable has no effect) is true. Small p-values indicate that the variable is a significant predictor.
vcov(fit)
## (Intercept) Processor_Speed RAM_Size Storage_Capacity
## (Intercept) 1.0707562236 -4.014133e-02 5.021959e-03 3.400532e-03
## Processor_Speed -0.0401413333 3.103245e-02 2.683521e-03 1.597563e-03
## RAM_Size 0.0050219588 2.683521e-03 7.262768e-04 3.772928e-04
## Storage_Capacity 0.0034005324 1.597563e-03 3.772928e-04 2.202216e-04
## Screen_Size -0.0441489825 1.174542e-03 1.880868e-04 1.165062e-04
## Weight -0.0366758386 1.117703e-03 -1.356607e-04 -4.215687e-05
## Price -0.0001161486 -5.304592e-05 -1.257617e-05 -7.342237e-06
## Screen_Size Weight Price
## (Intercept) -4.414898e-02 -3.667584e-02 -1.161486e-04
## Processor_Speed 1.174542e-03 1.117703e-03 -5.304592e-05
## RAM_Size 1.880868e-04 -1.356607e-04 -1.257617e-05
## Storage_Capacity 1.165062e-04 -4.215687e-05 -7.342237e-06
## Screen_Size 3.377400e-03 -5.652817e-04 -3.856630e-06
## Weight -5.652817e-04 1.274028e-02 1.273001e-06
## Price -3.856630e-06 1.273001e-06 2.449037e-07
#Ans) The variance-covariance matrix for the coefficients in my model fit shows the estimated covariance between each pair of coefficients. This matrix is useful for understanding the uncertainty in Ir coefficient estimates and for calculating confidence intervals.Each element in the matrix represents the covariance between two coefficients.The diagonal elements of the matrix (from top left to bottom right) represent the variance of each coefficient estimate. The square root of these values gives the standard error of each coefficient estimate. The off-diagonal elements represent the covariance between different coefficient estimates. Positive values indicate that the coefficients tend to vary together, while negative values indicate that they tend to vary in opposite directions.
plot(fit)
#Ans) The plots play a key role in highlighting important issues and verifying the model's assumptions. They aid in visualizing the degree to which the model matches the data. A good model fit is indicated by random scatter in the residuals vs fitted plot, a straight line in the Q-Q plot, random scatter in the Scale-Location plot, and no influential outliers in the Residuals vs Leverage plot.
r_squared <- summary(fit)$r.squared
r_squared
## [1] 0.01296368
#Ans) Model accuracy is around 13%.
library(factoextra)
library(FactoMineR)
library(psych)
library(ggplot2)
library(cowplot)
library(caret)
## Loading required package: lattice
library(e1071)
library(pROC)
## Type 'citation("pROC")' for a citation.
##
## Attaching package: 'pROC'
## The following objects are masked from 'package:stats':
##
## cov, smooth, var
Laptop <- read.csv("/Users/tusharkishan/Desktop/Multivariate/Assignment\ 1/Laptop_price.csv")
str(Laptop)
## 'data.frame': 202 obs. of 7 variables:
## $ Brand : chr "Asus" "Acer" "Lenovo" "Acer" ...
## $ Processor_Speed : num 3.83 2.91 3.24 3.81 3.27 ...
## $ RAM_Size : int 16 4 4 16 32 16 32 4 4 32 ...
## $ Storage_Capacity: int 512 1000 256 512 1000 256 256 256 512 512 ...
## $ Screen_Size : num 11.2 11.3 11.9 12.3 15 ...
## $ Weight : num 2.64 3.26 2.03 4.57 4.19 ...
## $ Price : num 17395 31608 9291 17437 32918 ...
#Ans)This data frame contains information about laptops, with each row representing a different laptop and each column representing a different attribute of the laptops. Here's what each variable represents:
#Brand: The brand of the laptop (e.g., Asus, Acer, Lenovo).
#Processor_Speed: The speed of the processor in GHz.
#RAM_Size: The amount of RAM in gigabytes (GB).
#Storage_Capacity: The storage capacity of the laptop's hard drive or SSD in gigabytes (GB).
#Screen_Size: The size of the laptop screen in inches.
#Weight: The weight of the laptop in kilograms
#Price: The price of the laptop in the local currency
Laptop$Brand_numeric <- ifelse(Laptop$Brand == "Acer", 0,
ifelse(Laptop$Brand == "Asus", 1,
ifelse(Laptop$Brand == "Dell", 2,
ifelse(Laptop$Brand == "HP", 3,
ifelse(Laptop$Brand == "Lenovo", 4, NA)))))
print(Laptop$Brand)
## [1] "Asus" "Acer" "Lenovo" "Acer" "Acer" "HP" "Lenovo" "Lenovo"
## [9] "Lenovo" "Acer" "Asus" "Lenovo" "Acer" "HP" "Asus" "HP"
## [17] "Asus" "Acer" "Dell" "Asus" "HP" "Acer" "Asus" "Dell"
## [25] "Dell" "Lenovo" "Lenovo" "HP" "Asus" "Asus" "Lenovo" "Asus"
## [33] "Asus" "Dell" "Lenovo" "Acer" "Lenovo" "Acer" "Dell" "HP"
## [41] "Asus" "Dell" "Asus" "HP" "HP" "Dell" "HP" "Acer"
## [49] "HP" "Asus" "Asus" "Asus" "Asus" "Acer" "Lenovo" "Dell"
## [57] "Asus" "HP" "Asus" "HP" "HP" "Asus" "Acer" "HP"
## [65] "HP" "Asus" "HP" "HP" "Asus" "Asus" "Dell" "Acer"
## [73] "Acer" "HP" "Acer" "HP" "Dell" "Asus" "Asus" "Asus"
## [81] "Acer" "Dell" "Acer" "Acer" "Dell" "Dell" "Dell" "Dell"
## [89] "Asus" "Lenovo" "Lenovo" "Dell" "Lenovo" "Lenovo" "Dell" "Lenovo"
## [97] "Acer" "HP" "HP" "Dell" "Asus" "Dell" "Asus" "HP"
## [105] "Dell" "Acer" "Lenovo" "Asus" "Lenovo" "Lenovo" "Dell" "Lenovo"
## [113] "Acer" "Lenovo" "Dell" "Acer" "HP" "Lenovo" "Dell" "HP"
## [121] "HP" "Asus" "Acer" "Lenovo" "Dell" "Asus" "Acer" "Asus"
## [129] "Acer" "Acer" "Lenovo" "Acer" "Asus" "Acer" "Lenovo" "Lenovo"
## [137] "Asus" "HP" "HP" "Acer" "Dell" "Acer" "Asus" "Asus"
## [145] "Asus" "Asus" "Asus" "Lenovo" "HP" "Asus" "Dell" "Dell"
## [153] "Dell" "Dell" "Lenovo" "Dell" "Asus" "Acer" "Dell" "Lenovo"
## [161] "Lenovo" "Dell" "Acer" "Dell" "Lenovo" "HP" "Asus" "Lenovo"
## [169] "Dell" "Asus" "Dell" "Dell" "HP" "Asus" "Asus" "HP"
## [177] "Lenovo" "Dell" "Acer" "Dell" "Dell" "Lenovo" "Dell" "HP"
## [185] "HP" "Asus" "Acer" "Dell" "Dell" "Lenovo" "HP" "Acer"
## [193] "Asus" "HP" "Asus" "Lenovo" "Lenovo" "Dell" "Acer" "Asus"
## [201] "HP" "Lenovo"
str(Laptop)
## 'data.frame': 202 obs. of 8 variables:
## $ Brand : chr "Asus" "Acer" "Lenovo" "Acer" ...
## $ Processor_Speed : num 3.83 2.91 3.24 3.81 3.27 ...
## $ RAM_Size : int 16 4 4 16 32 16 32 4 4 32 ...
## $ Storage_Capacity: int 512 1000 256 512 1000 256 256 256 512 512 ...
## $ Screen_Size : num 11.2 11.3 11.9 12.3 15 ...
## $ Weight : num 2.64 3.26 2.03 4.57 4.19 ...
## $ Price : num 17395 31608 9291 17437 32918 ...
## $ Brand_numeric : num 1 0 4 0 0 3 4 4 4 0 ...
Laptop$Brand <- as.factor(Laptop$Brand)
str(Laptop)
## 'data.frame': 202 obs. of 8 variables:
## $ Brand : Factor w/ 5 levels "Acer","Asus",..: 2 1 5 1 1 4 5 5 5 1 ...
## $ Processor_Speed : num 3.83 2.91 3.24 3.81 3.27 ...
## $ RAM_Size : int 16 4 4 16 32 16 32 4 4 32 ...
## $ Storage_Capacity: int 512 1000 256 512 1000 256 256 256 512 512 ...
## $ Screen_Size : num 11.2 11.3 11.9 12.3 15 ...
## $ Weight : num 2.64 3.26 2.03 4.57 4.19 ...
## $ Price : num 17395 31608 9291 17437 32918 ...
## $ Brand_numeric : num 1 0 4 0 0 3 4 4 4 0 ...
#Ans) To guarantee that R recognizes the category column, our predictor variable, we turn it into components. This transformation results in five levels for the factors.
logistic <- glm(Brand ~ ., data=Laptop, family="binomial")
## Warning: glm.fit: algorithm did not converge
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
summary(logistic)
##
## Call:
## glm(formula = Brand ~ ., family = "binomial", data = Laptop)
##
## Coefficients:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) -2.351e+01 9.158e+04 0.000 1.000
## Processor_Speed -6.881e-02 1.534e+04 0.000 1.000
## RAM_Size -3.917e-02 2.395e+03 0.000 1.000
## Storage_Capacity -1.298e-02 1.304e+03 0.000 1.000
## Screen_Size 1.550e-02 4.731e+03 0.000 1.000
## Weight -1.100e-01 1.062e+04 0.000 1.000
## Price 4.262e-04 4.341e+01 0.000 1.000
## Brand_numeric 4.725e+01 1.834e+04 0.003 0.998
##
## (Dispersion parameter for binomial family taken to be 1)
##
## Null deviance: 1.8935e+02 on 201 degrees of freedom
## Residual deviance: 9.2533e-09 on 194 degrees of freedom
## AIC: 16
##
## Number of Fisher Scoring iterations: 25
#Ans) The logistic regression model summary provides estimates for the coefficients of the predictorsand the intercept.Here are some inferences based on the summary:
#Intercept: The intercept is not statistically significant (p = 0.672), indicating that when all predictors are zero, the log-odds of the response variable being in the "Brand" category is not significantly different from zero.
#Predictor coefficients: None of the predictor coefficients (Processor_Speed, RAM_Size, Storage_Capacity, Screen_Size, Weight, Price) are statistically significant (all p > 0.05), indicating that these variables do not have a significant impact on the log-odds of the response variable.
#Deviance: The residual deviance is 186.04 on 195 degrees of freedom, indicating that the model does not fit the data well. A lower deviance value indicates a better fit, but it should be interpreted in comparison to other models.
#AIC: The AIC (Akaike Information Criterion) is 200.04, which is a measure of the model's goodness of fit. Lower AIC values indicate better fitting models, but it should be compared with other models to determine the best one.
new_data <- data.frame(probability.of.Brand=logistic$fitted.values,Brand=Laptop$Brand)
new_data_2 <- new_data[order(new_data$probability.of.Brand, decreasing=FALSE),]
new_data$rank <- 1:nrow(new_data)
ggplot(data = new_data, aes(x = rank, y = probability.of.Brand)) +
geom_point(aes(color = Brand), alpha = 1, shape = 1, stroke = 1) +
xlab("Index") +
ylab("Predicted probability of Quality")
#Ans)A scatter plot of probability.of.Brand against rank is where each point is colored based on the Brand variable.We can determine that the logistic regression assumptions are satisfied if there is no overlap.
data_new <- predict(logistic,newdata=Laptop,type="response" )
data_new
## 1 2 3 4 5 6
## 1.000000e+00 5.869156e-11 1.000000e+00 4.071173e-11 3.193982e-11 1.000000e+00
## 7 8 9 10 11 12
## 1.000000e+00 1.000000e+00 1.000000e+00 3.806412e-11 1.000000e+00 1.000000e+00
## 13 14 15 16 17 18
## 8.413941e-11 1.000000e+00 1.000000e+00 1.000000e+00 1.000000e+00 5.021658e-11
## 19 20 21 22 23 24
## 1.000000e+00 1.000000e+00 1.000000e+00 4.870606e-11 1.000000e+00 1.000000e+00
## 25 26 27 28 29 30
## 1.000000e+00 1.000000e+00 1.000000e+00 1.000000e+00 1.000000e+00 1.000000e+00
## 31 32 33 34 35 36
## 1.000000e+00 1.000000e+00 1.000000e+00 1.000000e+00 1.000000e+00 4.944439e-11
## 37 38 39 40 41 42
## 1.000000e+00 3.427833e-11 1.000000e+00 1.000000e+00 1.000000e+00 1.000000e+00
## 43 44 45 46 47 48
## 1.000000e+00 1.000000e+00 1.000000e+00 1.000000e+00 1.000000e+00 5.279916e-11
## 49 50 51 52 53 54
## 1.000000e+00 1.000000e+00 1.000000e+00 1.000000e+00 1.000000e+00 3.991887e-11
## 55 56 57 58 59 60
## 1.000000e+00 1.000000e+00 1.000000e+00 1.000000e+00 1.000000e+00 1.000000e+00
## 61 62 63 64 65 66
## 1.000000e+00 1.000000e+00 5.241985e-11 1.000000e+00 1.000000e+00 1.000000e+00
## 67 68 69 70 71 72
## 1.000000e+00 1.000000e+00 1.000000e+00 1.000000e+00 1.000000e+00 5.851057e-11
## 73 74 75 76 77 78
## 8.531934e-11 1.000000e+00 5.751008e-11 1.000000e+00 1.000000e+00 1.000000e+00
## 79 80 81 82 83 84
## 1.000000e+00 1.000000e+00 4.526826e-11 1.000000e+00 4.638538e-11 5.732135e-11
## 85 86 87 88 89 90
## 1.000000e+00 1.000000e+00 1.000000e+00 1.000000e+00 1.000000e+00 1.000000e+00
## 91 92 93 94 95 96
## 1.000000e+00 1.000000e+00 1.000000e+00 1.000000e+00 1.000000e+00 1.000000e+00
## 97 98 99 100 101 102
## 6.040409e-11 1.000000e+00 1.000000e+00 1.000000e+00 1.000000e+00 1.000000e+00
## 103 104 105 106 107 108
## 1.000000e+00 1.000000e+00 1.000000e+00 5.110236e-11 1.000000e+00 1.000000e+00
## 109 110 111 112 113 114
## 1.000000e+00 1.000000e+00 1.000000e+00 1.000000e+00 6.492951e-11 1.000000e+00
## 115 116 117 118 119 120
## 1.000000e+00 2.971719e-11 1.000000e+00 1.000000e+00 1.000000e+00 1.000000e+00
## 121 122 123 124 125 126
## 1.000000e+00 1.000000e+00 6.307762e-11 1.000000e+00 1.000000e+00 1.000000e+00
## 127 128 129 130 131 132
## 4.651047e-11 1.000000e+00 6.083885e-11 5.038607e-11 1.000000e+00 4.745050e-11
## 133 134 135 136 137 138
## 1.000000e+00 3.844906e-11 1.000000e+00 1.000000e+00 1.000000e+00 1.000000e+00
## 139 140 141 142 143 144
## 1.000000e+00 3.152233e-11 1.000000e+00 6.076245e-11 1.000000e+00 1.000000e+00
## 145 146 147 148 149 150
## 1.000000e+00 1.000000e+00 1.000000e+00 1.000000e+00 1.000000e+00 1.000000e+00
## 151 152 153 154 155 156
## 1.000000e+00 1.000000e+00 1.000000e+00 1.000000e+00 1.000000e+00 1.000000e+00
## 157 158 159 160 161 162
## 1.000000e+00 4.557058e-11 1.000000e+00 1.000000e+00 1.000000e+00 1.000000e+00
## 163 164 165 166 167 168
## 2.969951e-11 1.000000e+00 1.000000e+00 1.000000e+00 1.000000e+00 1.000000e+00
## 169 170 171 172 173 174
## 1.000000e+00 1.000000e+00 1.000000e+00 1.000000e+00 1.000000e+00 1.000000e+00
## 175 176 177 178 179 180
## 1.000000e+00 1.000000e+00 1.000000e+00 1.000000e+00 4.177512e-11 1.000000e+00
## 181 182 183 184 185 186
## 1.000000e+00 1.000000e+00 1.000000e+00 1.000000e+00 1.000000e+00 1.000000e+00
## 187 188 189 190 191 192
## 5.649073e-11 1.000000e+00 1.000000e+00 1.000000e+00 1.000000e+00 3.633369e-11
## 193 194 195 196 197 198
## 1.000000e+00 1.000000e+00 1.000000e+00 1.000000e+00 1.000000e+00 1.000000e+00
## 199 200 201 202
## 3.312535e-11 1.000000e+00 1.000000e+00 1.000000e+00
#Ans) We predict the response variable (Brand) for data stored in the Laptop dataset. The predicted probabilities of each level of the response variable (Brand) for each observation in the Laptop dataset is calculated.
data_2 <- factor(ifelse(data_new > 0.5, "Acer", "Not Acer"), levels = levels(Laptop$Brand))
data_2 <- factor(data_2, levels = levels(Laptop$Brand))
#Ans) The Laptop dataset set has 5 variable brands. I have taken the Brand Acer as my reference brand. This reference choice is arbitrary and doesn't imply that Acer is more important or significant than the other brands; it simply serves as a baseline for comparison. Essentially, the above code categorizes the predicted probabilities into two groups based on whether they exceed the threshold of 0.5, with "Acer" indicating that the probability is high enough to predict an Acer brand and "Not Acer" indicating that it is not.
confusionMatrix(data_2, Laptop$Brand)
## Confusion Matrix and Statistics
##
## Reference
## Prediction Acer Asus Dell HP Lenovo
## Acer 0 49 43 36 38
## Asus 0 0 0 0 0
## Dell 0 0 0 0 0
## HP 0 0 0 0 0
## Lenovo 0 0 0 0 0
##
## Overall Statistics
##
## Accuracy : 0
## 95% CI : (0, 0.022)
## No Information Rate : 0.2952
## P-Value [Acc > NIR] : 1
##
## Kappa : 0
##
## Mcnemar's Test P-Value : NA
##
## Statistics by Class:
##
## Class: Acer Class: Asus Class: Dell Class: HP
## Sensitivity NA 0.0000 0.000 0.0000
## Specificity 0 1.0000 1.000 1.0000
## Pos Pred Value NA NaN NaN NaN
## Neg Pred Value NA 0.7048 0.741 0.7831
## Prevalence 0 0.2952 0.259 0.2169
## Detection Rate 0 0.0000 0.000 0.0000
## Detection Prevalence 1 0.0000 0.000 0.0000
## Balanced Accuracy NA 0.5000 0.500 0.5000
## Class: Lenovo
## Sensitivity 0.0000
## Specificity 1.0000
## Pos Pred Value NaN
## Neg Pred Value 0.7711
## Prevalence 0.2289
## Detection Rate 0.0000
## Detection Prevalence 0.0000
## Balanced Accuracy 0.5000
#Ans)This confusion matrix shows the classification results of my model compared to the actual laptop brands. The other brands have zero predictions.Here's a breakdown of the confusion matrix:
#Accuracy: The overall accuracy of the model is 0, which means it is not predicting any brand correctly.
#Specificity: Specificity is high for all classes except "Acer," which makes sense because the model is only predicting "Acer," resulting in high specificity for other classes (since it's correctly not predicting them).
#Sensitivity: Sensitivity is not calculated for "Acer" because there are no true positives for "Acer" in the predictions.
#Kappa: The kappa value is 0, indicating no agreement between the predictions and the actual labels.
library(ggplot2)
library(memisc)
## Loading required package: MASS
##
## Attaching package: 'MASS'
## The following object is masked from 'package:dplyr':
##
## select
##
## Attaching package: 'memisc'
## The following object is masked from 'package:magrittr':
##
## %$%
## The following object is masked from 'package:ggplot2':
##
## syms
## The following objects are masked from 'package:dplyr':
##
## collect, recode, rename, syms
## The following objects are masked from 'package:stats':
##
## contr.sum, contr.treatment, contrasts
## The following object is masked from 'package:base':
##
## as.array
library(ROCR)
library(dplyr)
library(klaR)
Laptop <- read.csv("/Users/tusharkishan/Desktop/Multivariate/Assignment\ 1/Laptop_price.csv")
str(Laptop)
## 'data.frame': 202 obs. of 7 variables:
## $ Brand : chr "Asus" "Acer" "Lenovo" "Acer" ...
## $ Processor_Speed : num 3.83 2.91 3.24 3.81 3.27 ...
## $ RAM_Size : int 16 4 4 16 32 16 32 4 4 32 ...
## $ Storage_Capacity: int 512 1000 256 512 1000 256 256 256 512 512 ...
## $ Screen_Size : num 11.2 11.3 11.9 12.3 15 ...
## $ Weight : num 2.64 3.26 2.03 4.57 4.19 ...
## $ Price : num 17395 31608 9291 17437 32918 ...
#Model Development
r1 <- lda(formula = Brand ~ ., data = Laptop)
r1
## Call:
## lda(Brand ~ ., data = Laptop)
##
## Prior probabilities of groups:
## Acer Asus Dell HP Lenovo
## 0.1782178 0.2425743 0.2128713 0.1782178 0.1881188
##
## Group means:
## Processor_Speed RAM_Size Storage_Capacity Screen_Size Weight Price
## Acer 2.703102 18.00000 602.8889 13.77047 3.481705 20248.98
## Asus 2.725965 14.53061 577.3061 14.04612 3.353800 19345.37
## Dell 2.719753 16.93023 581.5814 14.39496 3.503828 19575.47
## HP 2.646197 14.11111 582.2222 14.03567 3.315187 19456.36
## Lenovo 2.524543 16.10526 610.3158 13.89843 3.422858 20302.57
##
## Coefficients of linear discriminants:
## LD1 LD2 LD3 LD4
## Processor_Speed 0.290676060 -0.6718284149 -0.165376269 -1.521169482
## RAM_Size 0.217432748 -0.0178922627 0.081228033 -0.114114003
## Storage_Capacity 0.097060563 0.0149555282 0.060634213 -0.091922251
## Screen_Size -0.146986619 -0.2916169716 0.469544792 0.023954639
## Weight 0.248803007 -0.4725100349 -0.045231122 -0.162733410
## Price -0.003219286 -0.0005004422 -0.002032376 0.003074179
##
## Proportion of trace:
## LD1 LD2 LD3 LD4
## 0.5291 0.3094 0.1546 0.0070
#Ans) The output predicts aptop brands (Acer, Asus, Dell, HP, Lenovo) based on several features (Processor_Speed, RAM_Size, Storage_Capacity, Screen_Size, Weight, Price).Prior probabilities: These are the estimated probabilities of each brand occurring in the dataset.
#Group means: These are the mean values of each feature for each brand.
#Coefficients of linear discriminants: These coefficients are used to linearly combine the features to form the discriminant functions (LD1, LD2, LD3, LD4).
#Proportion of trace: This indicates the proportion of the total variance explained by each discriminant function. The first discriminant function (LD1) explains 52.91% of the variance, the second (LD2) explains 30.94%, the third (LD3) explains 15.46%, and the fourth (LD4) explains 0.70%.
#finding out the in-between group variance of the linear discriminants
r2 <- lda(formula = Brand ~ ., data = Laptop, CV=TRUE)
r2
## $class
## [1] Acer Asus Asus Asus Dell Lenovo Acer Asus Lenovo Dell
## [11] Asus Acer Asus Asus Asus Dell Lenovo Dell Acer Dell
## [21] Asus Dell Lenovo Asus Asus Asus Asus Asus Lenovo Asus
## [31] Acer Acer Dell Asus Dell Asus Dell Dell Dell Asus
## [41] Asus Lenovo Dell Acer Asus Asus Asus Dell Asus Asus
## [51] HP Acer Lenovo Asus Asus Asus Dell Asus Asus Asus
## [61] Lenovo Asus Asus Asus Asus Acer Acer Asus Dell Dell
## [71] Lenovo Lenovo Asus Dell Asus Dell Acer Dell Dell Lenovo
## [81] Asus Asus Lenovo Asus Dell Asus Lenovo Asus Asus Lenovo
## [91] Acer Asus Asus Asus Asus Asus Asus Lenovo Asus Acer
## [101] Asus Asus Lenovo Lenovo Asus Lenovo Asus Asus Dell Asus
## [111] Dell Asus Asus Dell Asus Acer Asus Lenovo Asus Asus
## [121] Asus Asus Dell Asus Dell Lenovo Asus Asus Asus Lenovo
## [131] Dell Asus Dell Lenovo Lenovo Asus Dell Asus Lenovo Dell
## [141] Asus Asus Dell Lenovo Asus Asus Dell Dell Asus Dell
## [151] Asus Asus Asus Asus Acer Dell HP Asus Dell Asus
## [161] Asus Lenovo Lenovo Asus Lenovo Asus Asus Dell Asus Lenovo
## [171] Asus Dell Lenovo Asus Acer Asus Asus Asus Lenovo Dell
## [181] Acer Dell Asus Acer Dell Asus Asus Lenovo Dell Acer
## [191] Dell Lenovo Dell Asus Dell Asus Asus Asus Dell Lenovo
## [201] Asus Dell
## Levels: Acer Asus Dell HP Lenovo
##
## $posterior
## Acer Asus Dell HP Lenovo
## 1 0.25412288 0.21496121 0.16514251 0.15709936 0.20867403
## 2 0.16364411 0.30290667 0.14012528 0.22554094 0.16778301
## 3 0.14719923 0.33614469 0.13618457 0.25470291 0.12576861
## 4 0.22344203 0.23148022 0.23095724 0.12910585 0.18501467
## 5 0.22144470 0.18420560 0.30754579 0.10921800 0.17758592
## 6 0.22673903 0.21305408 0.17841044 0.12902907 0.25276739
## 7 0.32105319 0.17131080 0.20433930 0.10707348 0.19622323
## 8 0.11205697 0.30598217 0.23052068 0.22308579 0.12835438
## 9 0.13404921 0.23127632 0.20963228 0.17984088 0.24520131
## 10 0.23805451 0.22411046 0.26241411 0.13520625 0.14021467
## 11 0.14525798 0.31051789 0.21624133 0.23467836 0.09330443
## 12 0.28372275 0.22868885 0.24299814 0.13026777 0.11432249
## 13 0.08025261 0.36472824 0.15121742 0.30888821 0.09491351
## 14 0.13693143 0.27757262 0.17039478 0.21916427 0.19593690
## 15 0.16162524 0.31408326 0.21601645 0.21434723 0.09392781
## 16 0.17665468 0.25612352 0.35669944 0.11878804 0.09173432
## 17 0.22775544 0.08794203 0.12723189 0.10001776 0.45705288
## 18 0.14953313 0.26614188 0.30544568 0.16334006 0.11553924
## 19 0.24924800 0.23264324 0.16036797 0.14122787 0.21651292
## 20 0.14092317 0.22218261 0.25178904 0.17926322 0.20584196
## 21 0.17592735 0.24036289 0.21738173 0.15044357 0.21588446
## 22 0.13786282 0.23599301 0.26039642 0.17693816 0.18880959
## 23 0.26917506 0.15160262 0.13766925 0.17181538 0.26973769
## 24 0.16595166 0.25922645 0.17988319 0.20972129 0.18521741
## 25 0.17183610 0.28421435 0.21473642 0.18619570 0.14301743
## 26 0.12095415 0.27335575 0.18521021 0.25849338 0.16198651
## 27 0.10605530 0.32632383 0.16175076 0.28288978 0.12298033
## 28 0.12882769 0.30868082 0.17017286 0.22670693 0.16561170
## 29 0.16185886 0.21958936 0.18206202 0.17990226 0.25658750
## 30 0.19171839 0.25258394 0.18058862 0.19829788 0.17681117
## 31 0.26044955 0.18225656 0.23378392 0.12936537 0.19414459
## 32 0.25860078 0.19542136 0.16735460 0.17338632 0.20523695
## 33 0.20527784 0.14308095 0.34224777 0.11510515 0.19428829
## 34 0.12701033 0.28200037 0.21234452 0.21644128 0.16220350
## 35 0.12067134 0.22145928 0.28235200 0.17183383 0.20368356
## 36 0.18321523 0.26934821 0.20153136 0.18702723 0.15887797
## 37 0.20593833 0.17979226 0.30854146 0.13478688 0.17094108
## 38 0.15785335 0.15500586 0.29493849 0.11366382 0.27853847
## 39 0.21688326 0.17767629 0.24659810 0.11957311 0.23926925
## 40 0.12935937 0.29674698 0.22464479 0.19864158 0.15060728
## 41 0.19403838 0.29102911 0.21650196 0.19750321 0.10092733
## 42 0.18264114 0.19248283 0.23840561 0.14423894 0.24223147
## 43 0.20993912 0.22913969 0.23241369 0.17693680 0.15157070
## 44 0.30043063 0.19294657 0.17148954 0.10815002 0.22698325
## 45 0.17597386 0.25806020 0.17105849 0.17554742 0.21936003
## 46 0.10640811 0.32217020 0.24574314 0.22120808 0.10447046
## 47 0.11976271 0.26329984 0.25896680 0.18078975 0.17718090
## 48 0.10487926 0.24288266 0.34724333 0.14254534 0.16244941
## 49 0.13753231 0.27268172 0.19295766 0.21221457 0.18461373
## 50 0.17916927 0.26033501 0.15638850 0.21994934 0.18415788
## 51 0.15447936 0.23425394 0.11897767 0.25754528 0.23474374
## 52 0.33611833 0.17148269 0.24336261 0.10892002 0.14011635
## 53 0.21172936 0.21454135 0.15168667 0.17631752 0.24572510
## 54 0.22196963 0.23852846 0.22128508 0.16361873 0.15459811
## 55 0.19687690 0.25208660 0.15727064 0.21230578 0.18146008
## 56 0.14955389 0.29252326 0.16880149 0.20322107 0.18590029
## 57 0.12148738 0.23522305 0.28610509 0.22440973 0.13277474
## 58 0.15081729 0.32899393 0.20034955 0.19379436 0.12604488
## 59 0.10928516 0.25446437 0.22938529 0.23193510 0.17493008
## 60 0.15166223 0.23721981 0.20113028 0.19055606 0.21943162
## 61 0.14611368 0.25469239 0.12930986 0.21150896 0.25837512
## 62 0.15428735 0.28927187 0.16923344 0.25155241 0.13565493
## 63 0.18330960 0.29290351 0.16021305 0.20726582 0.15630802
## 64 0.17022237 0.26682843 0.18143687 0.18503128 0.19648105
## 65 0.13781536 0.30973475 0.26753053 0.16454590 0.12037346
## 66 0.29364850 0.18343139 0.15505178 0.16970448 0.19816386
## 67 0.31171577 0.16164407 0.18973168 0.08671450 0.25019398
## 68 0.15824922 0.28867316 0.17354034 0.21319895 0.16633833
## 69 0.15275085 0.19039733 0.30078369 0.17573857 0.18032957
## 70 0.15146405 0.18962138 0.27397926 0.14598680 0.23894851
## 71 0.14698142 0.20144215 0.19158373 0.16514008 0.29485261
## 72 0.13161164 0.24483472 0.11488582 0.22453406 0.28413376
## 73 0.07681638 0.35732399 0.21914677 0.24891819 0.09779467
## 74 0.26321859 0.16782059 0.37415641 0.05545161 0.13935280
## 75 0.13482886 0.24964484 0.19573309 0.20374908 0.21604412
## 76 0.17869469 0.21308456 0.31839532 0.12470080 0.16512463
## 77 0.26613459 0.19782167 0.20427963 0.12701858 0.20474553
## 78 0.14806500 0.22279291 0.29435262 0.20750809 0.12728138
## 79 0.15256441 0.18908481 0.26481630 0.21198917 0.18154531
## 80 0.18242075 0.22377475 0.12146822 0.21976057 0.25257570
## 81 0.19179184 0.26485182 0.24014341 0.16653017 0.13668276
## 82 0.12354597 0.30294766 0.25271276 0.20670959 0.11408402
## 83 0.16997555 0.20984213 0.14772698 0.17974044 0.29271491
## 84 0.11910236 0.28150232 0.22034159 0.21613881 0.16291492
## 85 0.17768451 0.21461832 0.29719305 0.15626595 0.15423817
## 86 0.15887261 0.26258925 0.21234918 0.17943809 0.18675087
## 87 0.20514796 0.21147980 0.12343960 0.18813176 0.27180087
## 88 0.12946497 0.26434671 0.17599079 0.22580419 0.20439334
## 89 0.17413701 0.29931379 0.18541672 0.21903493 0.12209755
## 90 0.21820234 0.18362875 0.22723608 0.14257226 0.22836058
## 91 0.27410320 0.21802324 0.17350446 0.14245942 0.19190968
## 92 0.12869168 0.27870334 0.14704120 0.24894576 0.19661801
## 93 0.20923955 0.22265733 0.21746564 0.18449061 0.16614688
## 94 0.13825284 0.23036870 0.21070820 0.19160976 0.22906050
## 95 0.12501354 0.30126719 0.18610166 0.21556098 0.17205664
## 96 0.14596741 0.30602226 0.20900569 0.20715124 0.13185341
## 97 0.12688416 0.29050952 0.26772402 0.18100850 0.13387380
## 98 0.29217251 0.13986691 0.16986301 0.07526709 0.32283048
## 99 0.13852234 0.34300441 0.20406281 0.20855138 0.10585905
## 100 0.26788367 0.17871600 0.14914331 0.13956809 0.26468893
## 101 0.10665812 0.25231092 0.24904737 0.21784998 0.17413361
## 102 0.27442464 0.28845520 0.14100239 0.18173211 0.11438566
## 103 0.22482771 0.16730909 0.21346816 0.16303119 0.23136385
## 104 0.16289853 0.20391004 0.24071740 0.14643391 0.24604012
## 105 0.17644108 0.24109147 0.18089575 0.18905245 0.21251925
## 106 0.15144330 0.23388170 0.12843335 0.20891662 0.27732502
## 107 0.20130870 0.23720459 0.23622367 0.18772536 0.13753768
## 108 0.12941282 0.27446262 0.19482973 0.23716782 0.16412700
## 109 0.15184092 0.22473282 0.23566822 0.16942124 0.21833681
## 110 0.19818692 0.26075064 0.19440122 0.17091121 0.17575000
## 111 0.25785985 0.23991612 0.26450256 0.13328138 0.10444009
## 112 0.13818184 0.26440263 0.16994948 0.21974892 0.20771713
## 113 0.11169103 0.28146205 0.20329048 0.23897819 0.16457823
## 114 0.18490172 0.23081395 0.25132083 0.16137965 0.17158385
## 115 0.16188127 0.27422980 0.21313684 0.17944478 0.17130732
## 116 0.26311634 0.16177630 0.19800765 0.11581997 0.26127974
## 117 0.17043784 0.36844271 0.11648572 0.21421400 0.13041973
## 118 0.19186330 0.22754467 0.14638604 0.18408463 0.25012136
## 119 0.20841060 0.25532874 0.13330544 0.18778459 0.21517063
## 120 0.11672281 0.33631057 0.16163132 0.24805013 0.13728518
## 121 0.11906509 0.26052164 0.17482106 0.19580471 0.24978751
## 122 0.17407592 0.31626270 0.18467329 0.22610550 0.09888259
## 123 0.08707592 0.31263639 0.32005494 0.19092205 0.08931071
## 124 0.19557615 0.24978379 0.11843633 0.22249576 0.21370796
## 125 0.22867199 0.20292842 0.30575017 0.11402298 0.14862644
## 126 0.17358589 0.19971209 0.23490719 0.15397051 0.23782431
## 127 0.20954792 0.26312898 0.23588336 0.16181977 0.12961996
## 128 0.21525297 0.28266162 0.16330013 0.25143756 0.08734771
## 129 0.13279187 0.27213464 0.21328550 0.21200637 0.16978162
## 130 0.11913463 0.18574515 0.14913928 0.17199185 0.37398910
## 131 0.18121357 0.20076281 0.32796460 0.14472214 0.14533687
## 132 0.18168326 0.25168063 0.22881153 0.18345147 0.15437310
## 133 0.16496943 0.18244734 0.35861028 0.12782781 0.16614515
## 134 0.21739012 0.18244011 0.16653108 0.14608053 0.28755816
## 135 0.14584385 0.22296887 0.22129986 0.18344155 0.22644588
## 136 0.16732725 0.27974549 0.24052995 0.17940870 0.13298861
## 137 0.17057706 0.24680869 0.27017691 0.18272202 0.12971533
## 138 0.14915801 0.28971097 0.14239907 0.19856894 0.22016301
## 139 0.15554428 0.20727299 0.21473680 0.14702080 0.27542513
## 140 0.23340926 0.17659744 0.24472173 0.12523413 0.22003745
## 141 0.13770559 0.23526430 0.19587978 0.19835327 0.23279706
## 142 0.15354964 0.30534030 0.20004886 0.19119423 0.14986696
## 143 0.13370522 0.21324105 0.26162482 0.19436698 0.19706192
## 144 0.21886861 0.19277277 0.16795202 0.15481417 0.26559243
## 145 0.11932312 0.25701331 0.24508933 0.21569833 0.16287591
## 146 0.11214209 0.26794207 0.25978381 0.20894667 0.15118536
## 147 0.16867551 0.23318091 0.29227765 0.16585127 0.14001465
## 148 0.26211113 0.21300060 0.29094480 0.12013068 0.11381278
## 149 0.15594111 0.27963759 0.18474888 0.21093372 0.16873870
## 150 0.12342955 0.19901795 0.27662300 0.19763791 0.20329159
## 151 0.18525032 0.26103075 0.14182985 0.21803055 0.19385853
## 152 0.16665087 0.29124747 0.21207578 0.18757411 0.14245177
## 153 0.14742242 0.30122728 0.21348663 0.20084870 0.13701497
## 154 0.17058604 0.25469062 0.23011136 0.17854217 0.16606980
## 155 0.30636348 0.21140490 0.20100785 0.13893043 0.14229333
## 156 0.22844128 0.22079404 0.28227834 0.13282818 0.13565816
## 157 0.09719503 0.26375954 0.19596950 0.26573831 0.17733762
## 158 0.20191085 0.25146662 0.19309751 0.14531719 0.20820782
## 159 0.16107438 0.24492020 0.27930001 0.16894459 0.14576081
## 160 0.18908327 0.25198055 0.12067221 0.20911831 0.22914567
## 161 0.19918725 0.23773445 0.20416722 0.16209552 0.19681556
## 162 0.22062053 0.18084223 0.09744358 0.14762674 0.35346692
## 163 0.26713940 0.15944924 0.16626459 0.12073856 0.28640821
## 164 0.14419997 0.29068354 0.29065381 0.17978432 0.09467835
## 165 0.23117557 0.17101805 0.19695203 0.13130520 0.26954915
## 166 0.14615381 0.34026362 0.20058511 0.20701184 0.10598561
## 167 0.17636739 0.25092938 0.15477747 0.23058318 0.18734258
## 168 0.19235734 0.19166960 0.25075844 0.13227122 0.23294340
## 169 0.13124751 0.26741289 0.19053093 0.21073525 0.20007342
## 170 0.17333939 0.21906533 0.18445682 0.17438434 0.24875412
## 171 0.18439683 0.29372349 0.17867119 0.20361918 0.13958931
## 172 0.19548180 0.16990609 0.28351247 0.11810050 0.23299914
## 173 0.20368432 0.21489985 0.17971727 0.12979806 0.27190051
## 174 0.16004788 0.23927463 0.23131873 0.18588660 0.18347215
## 175 0.24550188 0.23081855 0.20987846 0.17299504 0.14080607
## 176 0.11585535 0.33864076 0.24313847 0.18730770 0.11505771
## 177 0.18266405 0.28461802 0.21298083 0.18873761 0.13099949
## 178 0.19920930 0.22418793 0.17119579 0.18905291 0.21635406
## 179 0.15792799 0.17869647 0.14980097 0.15180545 0.36176913
## 180 0.14085823 0.21814161 0.26372854 0.16008330 0.21718832
## 181 0.31992634 0.17876766 0.19703898 0.11034903 0.19391799
## 182 0.17128906 0.19685565 0.24101772 0.17221750 0.21862006
## 183 0.11467540 0.35688643 0.12933523 0.29099980 0.10810314
## 184 0.33747341 0.14243949 0.20428020 0.06426847 0.25153843
## 185 0.13709666 0.23813673 0.27140291 0.14552966 0.20783403
## 186 0.20127246 0.26699673 0.20596057 0.17865893 0.14711132
## 187 0.09810086 0.24035092 0.22580930 0.20668840 0.22905052
## 188 0.18849500 0.11570339 0.16870882 0.09405483 0.43303796
## 189 0.20286368 0.25652240 0.30213181 0.14964568 0.08883643
## 190 0.27458659 0.19432378 0.15877505 0.13488616 0.23742842
## 191 0.19123875 0.24141069 0.29529001 0.13831904 0.13374152
## 192 0.21853240 0.17476480 0.20925617 0.12577444 0.27167219
## 193 0.14846202 0.18811884 0.27953815 0.15925076 0.22463023
## 194 0.13916913 0.28537759 0.22409992 0.15798151 0.19337185
## 195 0.16757312 0.22112368 0.28856126 0.16168385 0.16105808
## 196 0.14950503 0.28805924 0.21799304 0.19383243 0.15061026
## 197 0.13064385 0.27295433 0.17371215 0.23383475 0.18885492
## 198 0.16084773 0.29566033 0.12108821 0.22882847 0.19357527
## 199 0.17224013 0.15692434 0.31439312 0.10461446 0.25182794
## 200 0.17219574 0.19618536 0.19441569 0.17558999 0.26161322
## 201 0.18522922 0.31237086 0.26701362 0.14476095 0.09062535
## 202 0.14163759 0.26414242 0.27212408 0.20631721 0.11577870
##
## $terms
## Brand ~ Processor_Speed + RAM_Size + Storage_Capacity + Screen_Size +
## Weight + Price
## attr(,"variables")
## list(Brand, Processor_Speed, RAM_Size, Storage_Capacity, Screen_Size,
## Weight, Price)
## attr(,"factors")
## Processor_Speed RAM_Size Storage_Capacity Screen_Size Weight
## Brand 0 0 0 0 0
## Processor_Speed 1 0 0 0 0
## RAM_Size 0 1 0 0 0
## Storage_Capacity 0 0 1 0 0
## Screen_Size 0 0 0 1 0
## Weight 0 0 0 0 1
## Price 0 0 0 0 0
## Price
## Brand 0
## Processor_Speed 0
## RAM_Size 0
## Storage_Capacity 0
## Screen_Size 0
## Weight 0
## Price 1
## attr(,"term.labels")
## [1] "Processor_Speed" "RAM_Size" "Storage_Capacity" "Screen_Size"
## [5] "Weight" "Price"
## attr(,"order")
## [1] 1 1 1 1 1 1
## attr(,"intercept")
## [1] 1
## attr(,"response")
## [1] 1
## attr(,".Environment")
## <environment: R_GlobalEnv>
## attr(,"predvars")
## list(Brand, Processor_Speed, RAM_Size, Storage_Capacity, Screen_Size,
## Weight, Price)
## attr(,"dataClasses")
## Brand Processor_Speed RAM_Size Storage_Capacity
## "character" "numeric" "numeric" "numeric"
## Screen_Size Weight Price
## "numeric" "numeric" "numeric"
##
## $call
## lda(formula = Brand ~ ., data = Laptop, CV = TRUE)
##
## $xlevels
## named list()
#Ans) The class column shows the predicted class for each observation, and the posterior columns show the posterior probabilities for each class. Each row corresponds to an observation, and each column corresponds to a class.These probabilities represent the model's confidence in each class prediction for that observation.
#Performing LDA with training sample
train <- sample(1:500, 95)
r3 <- lda(Brand ~ ., data = Laptop, prior = c(0.2, 0.2, 0.2, 0.2, 0.2), subset = train)
r3
## Call:
## lda(Brand ~ ., data = Laptop, prior = c(0.2, 0.2, 0.2, 0.2, 0.2),
## subset = train)
##
## Prior probabilities of groups:
## Acer Asus Dell HP Lenovo
## 0.2 0.2 0.2 0.2 0.2
##
## Group means:
## Processor_Speed RAM_Size Storage_Capacity Screen_Size Weight Price
## Acer 2.450871 19.42857 684.5714 13.70612 3.469647 22789.66
## Asus 3.081061 16.00000 724.0000 14.76269 3.619811 23876.60
## Dell 2.983813 19.20000 432.8000 14.58813 3.573719 15278.92
## HP 2.642577 10.00000 384.0000 14.82866 3.169132 13237.81
## Lenovo 2.305936 14.00000 670.6667 14.02378 3.240275 21997.40
##
## Coefficients of linear discriminants:
## LD1 LD2 LD3 LD4
## Processor_Speed -0.469065748 1.648417417 -0.210631035 0.742831595
## RAM_Size 0.012924448 0.060089433 0.000771602 0.314346683
## Storage_Capacity -0.027437225 0.039514834 -0.032439674 0.163571293
## Screen_Size -0.387509762 0.170181983 -0.195673529 0.091098610
## Weight 0.209997290 0.555371779 0.294307983 0.318285903
## Price 0.001014421 -0.001269726 0.001015932 -0.005444459
##
## Proportion of trace:
## LD1 LD2 LD3 LD4
## 0.5811 0.3204 0.0932 0.0053
#Ans) Here's the summary of my findings
#Prior Probabilities of Groups: These are the prior probabilities for each class (brand) in Ir dataset. In this case, I've set them to be equal (0.2 for each brand).
#Group Means: These are the mean values of the predictor variables (Processor_Speed, RAM_Size, Storage_Capacity, Screen_Size, Weight, Price) for each brand. They provide insight into how the brands differ in terms of these features.
#Coefficients of Linear Discriminants: These coefficients are used to construct linear combinations of the predictor variables that best separate the classes. They indicate the importance of each predictor in the classification.
#Proportion of Trace: This shows the proportion of total variance in the data explained by each linear discriminant. In this case, LD1 explains 58.6% of the variance, LD2 explains 30.9%, LD3 explains 7.9%, and LD4 explains 2.5%.
#Making Predictions
llda1 = predict(object = r3, newdata = Laptop[-train, ])
head(llda1$class)
## [1] Asus Acer HP Asus Asus Acer
## Levels: Acer Asus Dell HP Lenovo
head(llda1$posterior, 50)
## Acer Asus Dell HP Lenovo
## 1 0.156396245 0.35255781 0.290041548 0.0577657346 0.14323866
## 2 0.448721387 0.25162839 0.052892187 0.0109627438 0.23579529
## 3 0.068159298 0.04269751 0.185633306 0.5549717310 0.14853815
## 4 0.067222035 0.55808843 0.309330215 0.0211797012 0.04417962
## 5 0.191641022 0.64887893 0.090566646 0.0021362029 0.06677719
## 6 0.387671002 0.03457773 0.232172971 0.0688740895 0.27670421
## 7 0.377396868 0.10136822 0.360182772 0.0182080506 0.14284409
## 8 0.005710252 0.03406908 0.132284011 0.7955031346 0.03243352
## 9 0.012473546 0.09381977 0.150909430 0.6304095461 0.11238771
## 12 0.312229035 0.32150957 0.275971655 0.0106168662 0.07967287
## 13 0.244957929 0.03321927 0.099366530 0.3262986229 0.29615765
## 14 0.160344471 0.00644098 0.088397261 0.4071830598 0.33763423
## 15 0.042409322 0.20778610 0.420253849 0.2841217724 0.04542895
## 17 0.206615763 0.04422462 0.270628032 0.0985594007 0.37997218
## 18 0.072511236 0.14739435 0.474219486 0.2288349890 0.07703994
## 19 0.069610284 0.23390002 0.490008770 0.1213041217 0.08517680
## 21 0.154537738 0.44593010 0.099496578 0.0440498802 0.25598570
## 23 0.831080652 0.00438954 0.003387375 0.0002477041 0.16089473
## 24 0.416144035 0.13976041 0.053157830 0.0231600801 0.36777765
## 27 0.032996604 0.00952448 0.079581824 0.7587041211 0.11919297
## 28 0.232856341 0.19213208 0.065387282 0.0973832849 0.41224101
## 29 0.051512842 0.14679672 0.220776517 0.3792520170 0.20166190
## 30 0.090056063 0.68275561 0.084468444 0.0274824237 0.11523746
## 31 0.646362321 0.13478990 0.041398523 0.0014830009 0.17596625
## 32 0.648056905 0.01040475 0.091742671 0.0198575341 0.22993814
## 34 0.053971782 0.10227439 0.192973423 0.4861963360 0.16458407
## 35 0.005756849 0.02748326 0.152190231 0.7649677645 0.04960190
## 36 0.334013035 0.07376768 0.333520527 0.0852160843 0.17348267
## 37 0.535334909 0.15040983 0.061955106 0.0049768062 0.24732335
## 38 0.135541917 0.05766226 0.407480898 0.1697714977 0.22954343
## 39 0.106765330 0.10202849 0.472034875 0.1598864850 0.15928482
## 41 0.132496601 0.18678949 0.461436483 0.1423607385 0.07691669
## 43 0.337038890 0.04829392 0.289265916 0.1125123386 0.21288893
## 44 0.569939312 0.08490817 0.136113016 0.0092865952 0.19975290
## 45 0.539143445 0.08492664 0.035645535 0.0095730614 0.33071132
## 46 0.015241872 0.18676692 0.214444056 0.5346266426 0.04892051
## 47 0.025371808 0.02615293 0.180145632 0.6734301897 0.09489944
## 48 0.002039369 0.16439158 0.299604986 0.5208727244 0.01309134
## 49 0.347040289 0.11434576 0.052280209 0.0465140478 0.43981969
## 50 0.385972524 0.04331905 0.114231560 0.0935922116 0.36288465
## 51 0.463366626 0.02935254 0.017003407 0.0159641532 0.47431328
## 53 0.151264328 0.08673583 0.339579905 0.2065430144 0.21587692
## 55 0.642953005 0.05555264 0.023641968 0.0040988543 0.27375353
## 56 0.012817785 0.07743181 0.225781977 0.6283813753 0.05558705
## 58 0.039852996 0.33336339 0.275191070 0.2764540019 0.07513854
## 59 0.045927901 0.04034271 0.120142817 0.6037899090 0.18979666
## 60 0.194386426 0.04520769 0.145901498 0.2264898133 0.38801457
## 62 0.237493608 0.02356891 0.175211777 0.3091743215 0.25455139
## 63 0.515947257 0.26300139 0.050760228 0.0047097674 0.16558136
## 64 0.413861852 0.04126651 0.124411012 0.0777285701 0.34273206
#Ans) Here's a brief explanation of the output
#llda1$class: This shows the predicted class for each observation in the test set. For example, the first observation is predicted to belong to the "Dell" class, the second to "Asus," and so on.
#llda1$posterior: This shows the posterior probabilities for each class for each observation. For example, for the first observation, the model assigns a high probability to the "Dell" class (0.73), indicating high confidence in this prediction.
head(llda1$x, 3)
## LD1 LD2 LD3 LD4
## 1 0.3199295 0.8536933 0.2652137 0.5125753
## 2 1.7043557 0.2227116 -0.7849547 -1.2892591
## 3 -1.1433851 -0.8898476 0.1405044 -1.5828065
#Ans) The llda1$x output shows the values of the linear discriminants (LD) for each observation in the test set. These values are essentially the coordinates of each observation in the LD space, which is a lower-dimensional space created by the LDA model to separate the classes.In my output each row represents an observation, and each column represents a different LD. For example, the first row shows the LD values for the first observation, where LD1 is -1.272716, LD2 is -1.6090542, LD3 is -1.4632172, and LD4 is 1.7946536. These LD values can be used to visualize the separation of classes in the LD space or for further analysis of the data.
#Plotting Residuals
plot(r1)
#Ans) We observe that there is a lot of overlap between the residuals
plot(r3)
#Ans) The overlap is way lesser compared to the previous plot
#Visualization
sample1 <- sample(c(TRUE, FALSE), nrow(Laptop), replace = T, prob = c(0.75,0.25))
train1 <- Laptop[sample1, ]
test1 <- Laptop[!sample1, ]
Laptop <- mean(Laptop, na.rm = TRUE)
## Warning in mean.default(Laptop, na.rm = TRUE): argument is not numeric or
## logical: returning NA
lda.Laptop <- lda(Brand ~ ., train1)
plot(lda.Laptop, col = as.integer(train1$Brand))
## Warning in pairs.default(X, panel = panel, ...): NAs introduced by coercion
#Ans) There is a lot of overlap between the residuals
#Accuracy
lda.train1 <- predict(lda.Laptop)
train1$lda <- lda.train1$class
table(train1$lda,train1$Storage_Capacity)
##
## 256 512 1000
## Acer 1 6 16
## Asus 16 11 7
## Dell 16 15 10
## HP 13 6 4
## Lenovo 7 9 19
#Ans)The accuracy of the model is not great on the training data
lda.test1 <- predict(lda.Laptop,test1)
test1$lda <- lda.test1$class
table(test1$lda,test1$Storage_Capacity)
##
## 256 512 1000
## Acer 0 2 1
## Asus 8 3 4
## Dell 6 2 2
## HP 2 2 0
## Lenovo 3 4 7
#Ans) The accuracy of the model of the test data is better than the training data
#Learning and Takeaways
#Ans) My project seems to involve a comprehensive analysis of laptop data. Here's a summary of the steps I've taken:
#Data Import: I imported the laptop dataset and handled missing values by imputing them with the mean.
#Data Exploration: I performed exploratory data analysis (EDA) to understand the structure and relationships in the dataset. This likely involved summary statistics, visualizations (e.g., histograms, scatter plots).
#Data Splitting: I split the dataset into training and testing sets, which is essential for model evaluation.
#Mean and Variance Analysis: I calculated the mean and variance of key variables in my dataset, such as price, RAM size, storage capacity, etc. This can help me understand the central tendency and variability of these features.
#PCA Analysis: Performed Principal Component Analysis (PCA) to reduce the dimensionality of in my dataset while retaining most of the variability. This helped me identify important features and patterns in my data.
#Clustering: Used clustering algorithms such as K-means or hierarchical clustering to group laptops based on their features. This helped me identify natural clusters or segments within my dataset.
#Factor Analysis: Conducted factor analysis to identify underlying factors or latent variables that explain the correlations among the observed variables. This helped me understand the underlying structure in my data.
#Multiple Regression: Used multiple regression to analyze the relationship between multiple independent variables (e.g., RAM size, storage capacity, etc.) and a dependent variable (Brand). This helped me understand how these features collectively affect the price of laptops based on their brand value.
#Logistic Regression: I've also used logistic regression for classification and evaluated its performance on the testing set.
#Linear Discriminant Analysis (LDA): I also used LDA to build a classification model to predict the brand of a laptop based on its Storage Capacity. I've trained the model on the training set and evaluated its performance on the testing set.
Note that the echo = FALSE parameter was added to the
code chunk to prevent printing of the R code that generated the
plot.